?
Solved

mySQLDump from PHP gives empty file

Posted on 2011-02-21
4
Medium Priority
?
695 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 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 2000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

770 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