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
Solved

mySQLDump from PHP gives empty file

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

856 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