Created
July 16, 2015 10:51
-
-
Save anonymous/5e36e4b79985abc14ace to your computer and use it in GitHub Desktop.
Remove Magento table prefix script with dry-run/test
This file contains hidden or 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