I would like to backup tables (with PHP) from a db if the table prefix is matching with a sub string. What I was trying and is not working
error_reporting(1);
$dbname = 'wp_dev';
if (!mysql_connect('127.0.0.1', 'root', '')) {
echo 'Connection Error';
exit;
}
$sql = "SHOW TABLES FROM $dbname LIKE 'wp_%'";
$result = mysql_query($sql);
if (!$result) {
echo "DB tables could not be listed\n";
echo 'MySQL Fehler: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
echo "<pre>Table: {$row[0]}\n</pre>";
system( 'mysqldump $dbname $row[0] > verlag_$row[0].sql');
}
mysql_free_result($result);
Here is a function for making bakups from db or only some tables
How to use:
You can modify the line:
$result = mysql_query(“SHOW TABLES”);
for the table präfix