Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Forked from anonymous/magento_deletedbprefix.php
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molotovbliss/3b3bf6b29f5f3753e50e to your computer and use it in GitHub Desktop.
Save molotovbliss/3b3bf6b29f5f3753e50e to your computer and use it in GitHub Desktop.
<?php
$database_host = "localhost";
$database_user = "username";
$database_password = "password";
$magento_database = "databasename";
$table_prefix = "prefixhere_";
$dryrun = true; // change to false when you want to commit changes
$db = mysql_connect($database_host, $database_user, $database_password);
mysql_select_db($magento_database);
$query = "SHOW TABLES";
$result = mysql_query($query) or die('### Error cannot connect to DB');
if ($dryrun) { echo "### No changes made, just testing <br />"; }
while($row = mysql_fetch_array($result)) {
$old_table = $row[0];
if ($new_table = preg_replace('/^'.$table_prefix.'/', '', $old_table)) {
if ($new_table != $old_table ) {
echo "Rename: " . $old_table . ", to: ". $new_table;
if (!$dryrun) {
$query = "RENAME TABLE `$old_table` TO `$new_table`";
mysql_query($query);
echo " -> DONE <br />";
} else { echo " -> Just checking <br />"; }
} else {
echo "Nothing to rename: " . $old_table . "<br />";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment