up vote 1 down vote favorite

Hi all,

I tried to dump a database:

<?php
$dbhost = "localhost";
$dbuser = "XXXX";
$dbpass = "XXXXXXXX";
$dbname = 'testdb';

$list = shell_exec ("C:\wamp\bin\mysql\mysql5.1.33\bin\mysqldump.exe $dbname  --user=$dbuser--password=$dbpass > dumpfile.sql");
?>

I tried both specified full path to mysqldump.exe or just use mysqldump, it still give me a 0kb dumpfile.sql

Details: Programming Language: PHP Database: MySql 5.XX OS(server): Windows Server 2003. (currently testing on Windows Vista machine)

EDIT @ Jeremy Heslop:

I tried:

shell_exec("C:\wamp\bin\mysql\mysql5.1.33\bin\mysqldump.exe --opt -h $dbhost -u$dbuser -p$dbpass $dbname > test.sql");

safe_mode = off

Still no luck man.

flag

Its is mysqldump not mysqldumb :D – unicornaddict Jan 14 at 3:16

3 Answers

up vote 1 down vote

Call me crazy, but don't you need to escape those backslashes in your path name? I'm guessing that the command fails, and since the error is on stderr, nothing gets written.

link|flag
i went crazy with you (removed the backslashes), nothing better, haha – mysqllearner Jan 14 at 3:45
That would be crazy since I was suggesting you double them :) shell_exec("C:\\wamp\\bin\\mysql\\mysql5.1.33\\bin\\mysqldump.exe --opt -h $dbhost -u$dbuser -p$dbpass $dbname > test.sql"); – James Jan 14 at 5:28
up vote 0 down vote

If I'm not mistaken the dbname should be at the end of the call after the --user and --password like this:

$list = shell_exec ("C:\wamp\bin\mysql\mysql5.1.33\bin\mysqldump.exe --user=$dbhost --password=$dbpass $dbname > dumpfile.sql");

Otherwise if that doesn't work there are some other things to look out for. Make sure the user that php runs as has permissions to write to that directory. Also make sure that php.ini has safe_mode = off as that could cause issues. Good luck!

link|flag
Edited my answer. Is it easier to create the mysqldump in batch file? – mysqllearner Jan 14 at 3:31
Not if you need to pass user/pass info from php, but if you don't then a batch file might be more straight forward. When you run the mysqldump command manually from the command line does it work as expected? James answer above could be leading to something. I would also try printing out the output of $list (output of shell_exec) to se if mysqldump is returning any errors. Try turning on verbose for mysqldump. – Jeremy Heslop Jan 14 at 13:34
up vote 0 down vote

I tried like this $result = system ("C:\wamp\mysql\bin\mysql.exe -u $username -p $password $dbname < $pathtomysqlfile"); and executed successfully then backup is restored.I'm wsing wamp.please try it..........

link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.