Last active
October 19, 2017 13:12
-
-
Save classmember/7ba3890ce344d6433d64659c3a22f66e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Database Creds | |
$DB_NAME = "<database goes here>"; | |
$DB_USER = "<username goes here>"; | |
$DB_PASS = "<password goes here>"; | |
$DB_HOST = "localhost"; | |
// Get list of tables | |
$get_tables = "mysql " | |
. "--host " . $DB_HOST | |
. " -p'" . $DB_PASS . "'" | |
. " -u " . $DB_USER | |
. " " . $DB_NAME | |
. " -rse " . "'SHOW TABLES;'"; | |
$tables_str = shell_exec($get_tables); | |
$tables = preg_split('/\s+/', $tables_str); | |
// Export Database | |
echo '<h2>Exporting database...</h2>'; | |
echo '<h4>Dumping Tables:</h4><ul>'; | |
foreach ($tables as $table) { | |
echo '<li>' . $table . '</li>'; | |
$dump_table = "mysqldump " | |
. "--host " . $DB_HOST | |
. " -p'" . $DB_PASS . "'" | |
. " -u " . $DB_USER | |
. " " . $DB_NAME | |
. " " . $table | |
. " >> " . $DB_NAME . ".sql"; | |
shell_exec($dump_table); | |
} | |
echo '</ul>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment