MySQL dump on WAMP server using PHP

血红的双手。 提交于 2021-02-09 08:32:41

问题


I am trying to dump the mysql database using a PHP file. I am using windows 7 OS.

but I am always getting error; This is my code

$user='root';
$pass='mypassword';
$host='localhost';
//$sql_file='db_backup.sql';
$cmd = "e:\\wamp\\bin\\mysql\\mysql5.6.12\\bin\\mysqldump -h$host  -u$user -p$pass hospitalerp > db_backup.sql";
exec($cmd, $output, $return);
if ($return != 0) { //0 is ok
    die('Error: ' . implode("\r\n", $output));
}

echo "dump complete";

Any suggestion will be greatly appreciated. Thanks.


回答1:


Ok I found the solution, may someone find it useful.

$user='root';
$pass='mypassword';
$host='localhost';

$cmd='e:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump --user='.$user.' --password='.$pass .' --host=localhost hospitalerp > db_backup4.sql';
//var_dump($cmd);exit;
exec($cmd, $output, $return);
if ($return != 0) { //0 is ok
    die('Error: ' . implode("\r\n", $output));
}

echo "dump complete";



回答2:


I note that mysqldump need the exe extension, just like:

$cmd='e:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump.exe --user='.$user.' --password='.$pass .' --host=localhost hospitalerp > db_backup4.sql';

I tried this on a Windows 10 PC



来源:https://stackoverflow.com/questions/29082539/mysql-dump-on-wamp-server-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!