Forked from anonymous/magento_deletedbprefix.php
Last active
August 29, 2015 14:25
-
-
Save molotovbliss/3b3bf6b29f5f3753e50e 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_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