Solved

mySQLDump from PHP gives empty file

Posted on 2011-02-21
4
675 Views
Last Modified: 2012-05-11
I'm trying to run mysqldump from PHP on a shared hosting server.  For some reason the dump is failing and  I'm getting a 0 length file.

I've included a code snippet and the results below.  Note that if I put in the "or die" it dies.
CODE SNIPPET
    //Verify that the DB and user info is good
    $dbLink = mysql_connect($custDBHost, $custDBUser,     $custDBPswd);
    print "dbLink = $dbLink<br><br>";
    $ok = mysql_select_db($custDBName, $dbLink);
    print "ok = $ok<br><br>";
	
    //Now try the dump	
    $command = "mysqldump --opt --h=$custDBHost --u=$custDBUser --p=$custDBPswd $custDBName  > $backupFile";
    system($command, $retVar); // or die('could not write file');
    print "retVar=$retVar";


OUTPUTOUTPUT
dbLink = Resource id #5

ok = 1

retVar=3

Open in new window

0
Comment
Question by:anAppBuilder
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 34945711
I'm a bit suspicious of this command

"mysqldump --opt --h=$custDBHost --u=$custDBUser --p=$custDBPswd $custDBName  > $backupFile";

Shouldn't those be single dashes? double dashes are for the complete words, so it should be -p or --password= and drop --opt unless it is for a very old version

try

"mysqldump -h $custDBHost  -u $custDBUser  -p $custDBP  $custDBName  > $backupFile";
or
"mysqldump -h $custDBHost  -u $custDBUser  --password=$custDBP $custDBName  > $backupFile";

because I think it prompts for just -p so --password= is better




0
 

Author Comment

by:anAppBuilder
ID: 34946210
Thank you bportlock.  

It still gets a 0 length file.  I posted the new snippet.

Is there a way to get more info about the error?
//Verify that the DB and user info is good
    $dbLink = mysql_connect($custDBHost, $custDBUser, $custDBPswd);
    print "dbLink = $dbLink<br><br>";
    $ok = mysql_select_db($custDBName, $dbLink);
    print "ok = $ok<br><br>";
		
    //run the command
    $command = "mysqldump -h $custDBHost -u $custDBUser -password=$custDBPswd $custDBName  > $backupFile";
    system($command, $retVar); // or die('could not write file');
    print "retVar=$retVar";

OUTPUT
dbLink = Resource id #5

ok = 1

retVar=2

Open in new window

0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 500 total points
ID: 34946314
Your command is incorrect. Use --password rather than -password (note the TWO leading dashes for a full word parameter, single dashes are for short parameters)  and make sure that all your variables contain valid data - no gaps or dots in database names and so forth
0
 

Author Comment

by:anAppBuilder
ID: 34946910
Thank you.  Adding the second dash works.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now