Help with MySQL dump

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ddragas
Forum Contributor
Posts: 445
Joined: Sun Apr 18, 2004 4:01 pm

Help with MySQL dump

Post by ddragas »

I've found this script somewhere on the net, and can't figure it out how to make it work on local machine.


Here is code

Code: Select all

<?php
//Full Source at http://www.ov-m.com/mysqlphpbak/

$MYSQL_SERVER="localhost";        // server name
$MYSQL_USER="root";            // authorized mysql user
$MYSQL_PASSWD="";            // authorized user password
$PATHTOMYSQLDUMP="C:/mysql/bin/";        // path to mysqldump utility

$DIRNAME="../backup/";     // where to do the backups
$DIRNAME.=date("dmY");                // add date identifier
$DIRNAME.="/";                    // add trailing slash

echo "Creating New Back Up Directory<br><br>";

echo "Using Directory : $DIRNAME<br>";


if (@mkdir ($DIRNAME,0700)) {
    echo "New Directory Created<br>";
} else {
    echo "Directory already exists!";
}

echo "Backing Up all Databases on $HOSTNAMEnn";

//***************************************************************************

mysql_connect($MYSQL_SERVER,$MYSQL_USER,$MYSQL_PASSWD);

$result = mysql_list_dbs();
$i = 0;
while ($i < mysql_num_rows ($result)) {
    $tb_names[$i] = mysql_tablename ($result, $i);
        $i++;
}
//***************************************************************************
// Loop through the table names, and do the dump.
//***************************************************************************
for ($i=0; $i<count($tb_names); $i++) {
    
    $COMMAND_DO=$PATHTOMYSQLDUMP. "mysqldump -h ".$MYSQL_SERVER." -u ".$MYSQL_USER." -p ".$MYSQL_PASSWD." ".$tb_names[$i]." > ".$DIRNAME.$tb_names[$i].".sql";

    echo $COMMAND_DO . "<br>";     // uncomment these lines if you want to see all
    flush();            // back-ups made on the server

    exec($COMMAND_DO);        // execute each backup

}

echo "nnDONE!n";



?>
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Ok, so where are you at this point? Have you edited the script for your own machine, i.e. set the variables at the top of the script to work with your setup? Are you getting any errors? Does the script display anything?

Is there some reason you can't just use 'mysqldump' from the command line?

Please be specific when posting.
Post Reply