Solved

mySQLDump from PHP gives empty file

Posted on 2011-02-21
4
683 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysql ide 10 40
Seeking info on how to integrate RETS feed based MLS data into a WordPress site 5 49
maybe no no httpd.conf 6 48
website maintenance mode 1 17
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

803 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