Jump to content


Photo

[SOLVED] shell_exec("mysqldump... ") creates 0-byte dump file....


  • Please log in to reply
5 replies to this topic

#1 obay

obay

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts

Posted 10 September 2007 - 04:54 AM

<?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??

#2 Daniel0

Daniel0

    Advanced Member

  • Administrators
  • 11,955 posts

Posted 10 September 2007 - 09:31 AM

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.

#3 effigy

effigy

    Advanced Member

  • Staff Alumni
  • 3,600 posts
  • LocationIL

Posted 10 September 2007 - 10:39 AM

Try using the full path to mysqldump, as well as redirecting STDERR to an output file.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#4 obay

obay

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts

Posted 11 September 2007 - 01:16 AM

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?

#5 obay

obay

    Advanced Member

  • Members
  • PipPipPip
  • 110 posts

Posted 11 September 2007 - 03:50 AM

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...")

=)

#6 Daniel0

Daniel0

    Advanced Member

  • Administrators
  • 11,955 posts

Posted 11 September 2007 - 07:41 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com