PHP Quick Hacks | JamiiForums | The Home of Great Thinkers

# PHP Quick Hacks

Discussion in 'Tech, Gadgets & Science Forum' started by emanuel.feruzi, Oct 5, 2009.

1. ### emanuel.feruziSenior Member

#1
Oct 5, 2009
Joined: Apr 25, 2009
Messages: 103
Trophy Points: 0
I had write a small script to allow someone to do a dump of the MySQL database that was later sent to them by email. It worked very well until we tried it on the productions server that was running on Windows and it broke.

I have rewritten it so that it works on Windows:-

PHP:
 <?php    /* variable declaration */    $db_user = "yourUsername";$db_password = "yourPassword";    $db_database = "yourDatabaseName";$db_server = "yourHostName";    //default: localhost    $backup_path = "C:\\path\\to\\backup\\folder\\"; //e.g$backup_path = "C:\\backups\\sqldumps\\";    $path_to_mysqldump = "C:\\path\\to\\mysql\\bin\\"; //e.g$path_to_mysqldump = "C:\\xampp\\mysql\\bin\\";    $filename = "backup".date("YmdHis").".sql"; //filename with a timestamp /*construction the command to be run */$command= "$path_to_mysqldump\\mysqldump.exe --add-drop-table --add-drop-database -h$db_server -u $db_user --password=$db_password $db_database >$filename ";         /* excution of the command */        exec($command,$dump, $status); /*checking the status of the command after runing */ if($status!=0){        echo "The execution was not successfull. An empty file has been created";    }else{        echo "The execution was successfull. Backup files is " . $backup_path.$filename ;    }?>  
I hope some finds this useful.