• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

PHP5 Anyone see what I'm doing wrong in this small script ... am crying at the moment

Jethro

Well-known member
#1
Code:
<?php

$dbhost = 'host';
$dbuser = 'user';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'database';
mysql_select_db($dbname) or die ("Database Selection Wrong");

$backupfile = "holycowitsdata.sql";
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupfile";
//echo($command);
system($command);

mysql_close($conn);

echo("done and dusted");
?>
It's generating the backupfile but is not actually dumping any data to it ....
 

g0rn

Well-known member
#6
By the way, you do not need to connect to the database from the php script, you only need to execute mysqldump command and it will connect and dump everything itself.
 

Jethro

Well-known member
#7
You have a space between -p and your password ($dbpass).
Thanks dude, working like a charm :)

g0rn am opening the database to ensure I have the correct details as this small script is being run over multiple dbs for a full scale move. An open ensures I have the correct details each time it's run.