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