emanuel.feruzi
Senior Member
- Apr 25, 2009
- 103
- 8
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:-
I hope some finds this useful.
Comments are welcome.
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 ;
}
?>
Comments are welcome.