Jump to content

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


Recommended Posts

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

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.