PHP, WEB

Backup MySQL with PHP

If you want to create a MySQL backup(sql file) through PHP, here is an easy way to do this:

1
2
3
$filename = path_for_db_backups . 'db_backup-' . date ( 'Ymd_His' ) . '.sql';
$command = 'mysqldump --opt -h ' . db_host . ' --user=' . db_admin_username . ' --password=' . db_admin_password . ' ' . db_name . ' > ' . $filename;
system ( $command );