469,338 Members | 8,161 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

Help with mysqldump...

Hello all.
Can anyone see why this snippet of code isnt dumping the databases using
mysqldump ?
All the credentials are correct (changed for the purpose of this post).

$host = "localhost";
$user = "root";
$pass = "password";
$database = "database";
$dbname = array ("1","2","3","4","5");
$savepath = "c:/inetpub/sqlbackup";
$date = date("mdy-hia");

$link = mysql_connect($host, $user, $pass) or die("Could not connect");
mysql_select_db($database) or die("Could not select database");

for ($i=0;$i<sizeof($dbname);$i++)
{
$filename = "$savepath/$dbname[$i]-$date.sql";
passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i]
$filename");

}

mysql_free_result($result);
mysql_close($link);
Jul 17 '05 #1
4 2411
Mangina wrote:
Hello all.
Can anyone see why this snippet of code isnt dumping the databases using
mysqldump ?
All the credentials are correct (changed for the purpose of this post).

$host = "localhost";
$user = "root";
$pass = "password";
$database = "database";
$dbname = array ("1","2","3","4","5");
$savepath = "c:/inetpub/sqlbackup";
$date = date("mdy-hia");

$link = mysql_connect($host, $user, $pass) or die("Could not connect");
mysql_select_db($database) or die("Could not select database");

for ($i=0;$i<sizeof($dbname);$i++)
{
$filename = "$savepath/$dbname[$i]-$date.sql";
passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i]
$filename");


}

mysql_free_result($result);
mysql_close($link);


I don't understand why "--opt" is in there.

Regards,

- Dan
http://blog.dantripp.com/
Jul 17 '05 #2
Checkyour mysql configuration (.my.cfg on unix). If you have
parameters set in [client] and not in [mysqldump] they take
precedience and you have problems. [client] seems to be a default set
of settings.

On Sun, 8 Feb 2004 20:03:21 -0900, Mangina <su*****@microsoft.com> wrote:


Hello all.
Can anyone see why this snippet of code isnt dumping the databases using
mysqldump ?
All the credentials are correct (changed for the purpose of this post).

$host = "localhost";
$user = "root";
$pass = "password";
$database = "database";
$dbname = array ("1","2","3","4","5");
$savepath = "c:/inetpub/sqlbackup";
$date = date("mdy-hia");

$link = mysql_connect($host, $user, $pass) or die("Could not connect");
mysql_select_db($database) or die("Could not select database");

for ($i=0;$i<sizeof($dbname);$i++)
{
$filename = "$savepath/$dbname[$i]-$date.sql";
passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i]
$filename");

}

mysql_free_result($result);
mysql_close($link);

--
Michael Vore, W3CCV M-ASA [Ka8]; WHIRL, ABC; CAW, CW, AAW
http://mike.vorefamily.net/ohmywoodness <-You'll find items of interest here
Jul 17 '05 #3
Mangina wrote:
Hello all.
Can anyone see why this snippet of code isnt dumping the databases using
mysqldump ?
All the credentials are correct (changed for the purpose of this post).
I think I found a couple of things. See below. =)

$host = "localhost";
$user = "root";
$pass = "password";
$database = "database";
$dbname = array ("1","2","3","4","5");
$savepath = "c:/inetpub/sqlbackup";
$date = date("mdy-hia");

$link = mysql_connect($host, $user, $pass) or die("Could not connect");
mysql_select_db($database) or die("Could not select database");
Above, you're specifying the database names... so unless you're running
a query to get the db names, the two lines above aren't necessary. If
you want to dump all the databases, it'd be easier to use the
"--all-databases" flag with mysqldump than it would be to ask the db for
all the names first.

for ($i=0;$i<sizeof($dbname);$i++)
{
$filename = "$savepath/$dbname[$i]-$date.sql";
passthru("c:/mysql/bin/mysqldump --opt -h$host -u$user -p$pass $dbname[$i]
$filename");


}

mysql_free_result($result);
mysql_close($link);


Same basic comment as above. Those two lines probably aren't necessary.

I'm assuming that you're on a windows machine with IIS. =) Why else
would one have a "C:" in their path name... and want to put stuff in
"inetpub?. ;)

Your mileage may vary... but the following worked for me. Please note
that this *won't work* if safe mode is on in your php.ini file. Also,
my machine (Apache/XP) choked on the forward slashes in the path to
mysqldump, so I put in escaped backslashes. T'would be a different path
on *nix.

<?php

$host = "localhost";
$user = "user";
$pass = "password";
$dbnames = array ("db1","db2");
$savepath = "c:/inetpub/sqlbackup";
$date = date("mdy-hia");

foreach($dbnames as $dbname)
{
$filename = $savepath.$dbname."-".$date.".sql";
$execCmd = "c:\\mysql\\bin\\mysqldump.exe -h$host -u$user -p$pass
$dbname >> $filename";
exec($execCmd);
}

?>

Regards,

- Dan
http://blog.dantripp.com/
Jul 17 '05 #4
"Dan Tripp" <th*******@MyEMailAddress.com> wrote in message
news:a%******************@newssvr25.news.prodigy.c om...

<?php

$host = "localhost";
$user = "user";
$pass = "password";
$dbnames = array ("db1","db2");
$savepath = "c:/inetpub/sqlbackup";
$date = date("mdy-hia");

foreach($dbnames as $dbname)
{
$filename = $savepath.$dbname."-".$date.".sql";
$execCmd = "c:\\mysql\\bin\\mysqldump.exe -h$host -u$user -p$pass
$dbname >> $filename";
exec($execCmd);
}

?>


Thank you very much for your help. I will try this out later tonight and
post back.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Thiko | last post: by
7 posts views Thread by Adam Smith | last post: by
reply views Thread by mcstayinskool | last post: by
1 post views Thread by Greg.Harabedian | last post: by
6 posts views Thread by Todd Cary | last post: by
6 posts views Thread by Robert Blackwell | last post: by
6 posts views Thread by Antoni | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.