Last Updated: February 25, 2016
·
1.896K
· teknonono

dump mysql using PHP script

// DB connection info
$host = "";
$user = "";
$pwd = "";
$db = "";
$backup_file = 'dbname'. date("Y-m-d-H-i-s");

// Connect to database.
try {
    $command = "mysqldump --opt -h $host -u $user -p $pwd dbname > $backup_file.sql";
    exec($command);
}
catch(Exception $e){
    die(var_dump($e));
}