1

I am trying to write a function that returns the whole dump of sql using this code:

$command = "C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin\\mysqldump --add-drop-table --host=$hostname
    --user=$username ";
if ($password) 
        $command.= "--password=". $password ." "; 
$command.= $dbname;
var_dump(terminal($command));

function terminal($cmd)
{
    if (function_exists('system'))
    {
        ob_start();
        system($cmd, $retVal);
        $output = ob_get_contents();
        ob_end_clean();
        $function_used = "system";
    }
    else if(function_exists('passthru'))
    {
        ob_start();
        passthru($cmd, $retVal);
        $output = ob_get_contents();
        ob_end_clean();
        $function_used = "passthru";
    }
    else if(function_exists('exec'))
    {
        exec($cmd, $output, $retVal);
        $output = implode("n", $output);
        $function_used = "exec";
    }
    else if(function_exists('shell_exec'))
    {
        $output = shell_exec($cmd);
        $function_used = "shell_exec";
    }
    else 
    {
        $output = "Cannot execute shell commands";
        $retVal = 1;
    }
     return array('output' => $output, 'returnValue' => $retVal, 'functionUsed' => $function_used);
}

The database credentials are correct when i run that command in a normal command line it get the desired result.

The problem is that when i try it using these command, either function i use i get always an empty string as an output. On the other hand the return value is always 1 which results to true i think and means that the function is executed correctly otherwise i will get a false return value.

For example i use the 'system' as it is the fist i encounter. Is it corrent how i am getting the output?

Regards

1 Answer 1

1

Since you have spaces in the path to the executable, you need to enclose it in double-quotes.

$command = "\"C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin\\mysqldump\" --add-drop-table --host=$hostname --user=$username ";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.