MySQL dumps with PHP - Good Tips

Posted on Jun 24, 2013
To make a MySQL Dump with PHP, you'll simply have to execute the following Command in PHP script:
(The code below as one line in your PHP-script).
passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser
--password=$dbpwd $dbname > $dump_file_name");

MYSQL-HOST = MySQL server adress (mysql15**
USERNAME = the username for the database.
PASSWORD = the password for the database.
DATABASENAME = the name on the database.

Another bit of code that does the same job, better coded maybe.
$dbhost   = "mysql15**";
$dbname   = "DATABASENAME";
$dbuser   = "USERNAME";
$dbpwd    = "PASSWORD";
$dumpfile = $dbname . "_" . date("Y-m-d_H-i-s") . ".sql";

passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser
--password=$dbpwd $dbname > $dump_file_name");

// report - disable with // if not needed

echo "$dumpfile "; passthru("tail -1 $dumpfile");

Turn OFF the SAFE MODE ! before using this code. It will create a SQL file in the same dir as the PHP-file. The SQL-files in your folder is good to go. Just click the link "Import database" and follow the instructions.

Leave a comment:

Thank you for your comment. After a while, our moderators will add it.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

© Twiwoo 2023 Cookie Policy