MySQL, PHP & HTML5 bannerMySQL, PHP & HTML5 banner

The PHP system() function is used to execute an external program. Because MySQL already has a built-in tool for creating MySQL database backups, mysqldump, let’s use it from our PHP script:

<?php
include 'config.php';
include 'opendb.php';
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);
include 'closedb.php';
?>

The following post offers an alternative to this strategy: How to use PHP To Backup & Restore a MySQL Database Table

By foxbeefly

PHP / MySQL Developer. HTML, CSS and some JavaScript.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from stylus

Subscribe now to keep reading and get access to the full archive.

Continue reading