mysqldump in .php file
What's wrong with the exec() function
<?php
exec('mysqldump --host=localhost --user=root --password="" testing > C:/Users/deleo/Desktop/newfile.sql');
?>
when I run this code it's nothing happen but only white screen
I expected the output .sql file with my database(testing) table structure and data itself
When I did this
`
<?php
define("BACKUP_PATH", "C:/Users/deleo/Desktop/");
$server_name = "localhost";
$username = "root";
$password = "";
$database_name = "testing";
$date_string = date("Ymd");
$cmd = "mysqldump --hex-blob --routines --skip-lock-tables --log-error=mysqldump_error.log -h {$server_name} -u {$username} -开发者_如何学Pythonp{$password} {$database_name} > " . BACKUP_PATH . "{$date_string}_{$database_name}.sql";
$arr_out = array();
unset($return);
exec($cmd, $arr_out, $return);
if($return !== 0) {
echo "mysqldump for {$server_name} : {$database_name} failed with a return code of {$return}\n\n";
echo "Error message was:\n";
$file = escapeshellarg("mysqldump_error.log");
$message = `tail -n 1 $file`;
echo "- $message\n\n";
}
?>
`
I got this error mysqldump for localhost : tapsihannibhey failed with a return code of 1 Error message was: -
Hey I'm not sure what you problem is but you might want to try this lib i'm working on (fully functional just adding features). ez-php-mysql-backup
精彩评论