Skip to content

Instantly share code, notes, and snippets.

@chope1
chope1 / backup.php
Created June 23, 2019 14:07 — forked from samuelkordik/backup.php
Simple PHP script to backup MySQL database and email results to me. Adapted from (here)[http://davidwalsh.name/backup-mysql-database-php] with improvements made including using MySQLi, gzipping the backup file (significantly reduces time to email), adding a timing function, and generally making more functional. Note two functions here left fairl…
<?php
/**
* Handles backing up database automatically and emailing it to me.
*/
date_default_timezone_set('America/Chicago'); // necessary in some server environments before using any Date/Time functions.
$timestart = microtime(true);
config(); // sets up constants and configurations for database credentials, error handling, etc. including using local environment specific options.
$filename = backup_tables(DB_HOST, DB_USER, DB_PASS, DB_NAME); // backs up data.