obay Posted September 10, 2007 Share Posted September 10, 2007 <?php $User = "root"; $Password = ""; $DatabaseName = "bcms6" $File = "mydump.sql"; $Results = shell_exec("mysqldump --allow-keywords --opt -u$User -p$Password $DatabaseName > $File"); ?> results in a blank (0 bytes) mydump.sql, saved in xampplite/htdocs/myfolder but when i use the shell shell>mysqldump --allow-keywords --opt -uroot -p bcms6 > mydump.sql it works just fine, mydump.sql saved in xampplite/mysql/bin (since i'm running mysql dump from that folder). what's wrong with my code? why does it produce 0 bytes? by the way, when i run from the shell, it asks for a password, and i press enter to provide the blank password. so i tried adding this line to my code: shell_exec(""); but still the same problem. 0-byte dump file.. help?? Link to comment https://forums.phpfreaks.com/topic/68678-solved-shell_execmysqldump-creates-0-byte-dump-file/ Share on other sites More sharing options...
Daniel0 Posted September 10, 2007 Share Posted September 10, 2007 Try $Results = shell_exec("mysqldump --allow-keywords --opt -u$User".!empty($Password) ? ' -p'.$Password : null." $DatabaseName > $File"); In that way you'll only send the -p argument if the password isn't empty. Link to comment https://forums.phpfreaks.com/topic/68678-solved-shell_execmysqldump-creates-0-byte-dump-file/#findComment-345353 Share on other sites More sharing options...
effigy Posted September 10, 2007 Share Posted September 10, 2007 Try using the full path to mysqldump, as well as redirecting STDERR to an output file. Link to comment https://forums.phpfreaks.com/topic/68678-solved-shell_execmysqldump-creates-0-byte-dump-file/#findComment-345400 Share on other sites More sharing options...
obay Posted September 11, 2007 Author Share Posted September 11, 2007 Try using the full path to mysqldump, if i do this, e.g "c:\xampplite\mysql\bin\mysqldump.exe ...", won't there be any issues when i upload this to my server? as well as redirecting STDERR to an output file. how do i do this? by the way, if mysqldump was able to create "mydump.sql" (even if empty), doesn't it mean it didn't return any errors? Link to comment https://forums.phpfreaks.com/topic/68678-solved-shell_execmysqldump-creates-0-byte-dump-file/#findComment-345808 Share on other sites More sharing options...
obay Posted September 11, 2007 Author Share Posted September 11, 2007 i found my answer my original code shell_exec("mysqldump... ") works on nix. my webserver is linux. while on windows, need to specify full path such as shell_exec(" c:\xampplite\mysql\bin\mysqldump...") =) Link to comment https://forums.phpfreaks.com/topic/68678-solved-shell_execmysqldump-creates-0-byte-dump-file/#findComment-345846 Share on other sites More sharing options...
Daniel0 Posted September 11, 2007 Share Posted September 11, 2007 i found my answer my original code shell_exec("mysqldump... ") works on nix. my webserver is linux. while on windows, need to specify full path such as shell_exec(" c:\xampplite\mysql\bin\mysqldump...") =) Or you could put C:\xampplite\mysql\bin in PATH. Link to comment https://forums.phpfreaks.com/topic/68678-solved-shell_execmysqldump-creates-0-byte-dump-file/#findComment-345956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.