Skip to content

Instantly share code, notes, and snippets.

@sarathlal-old
Last active February 10, 2016 04:16
Show Gist options
  • Save sarathlal-old/fa2f3ce8e80c516b2273 to your computer and use it in GitHub Desktop.
Save sarathlal-old/fa2f3ce8e80c516b2273 to your computer and use it in GitHub Desktop.
Place this file in Magento installation root folder. Then change the database details & run the script. Last, change the database prefix in app/etc/local.xml.
<?php
//Add Database details
$database_host = "localhost";// DB Host
$database_user = "dbuser"; // DB User Name
$database_password = "dbpassword"; // DB Password
$magento_database = "dbname"; //DB Name
$table_prefix = "dbprefix_"; // DB Prefix
//Do the action
$db = mysql_connect($database_host, $database_user, $database_password);
mysql_select_db($magento_database);
$query = "SHOW TABLES";
$result = mysql_query($query) or die('Err');
while($row = mysql_fetch_array($result)) {
$old_table = $row[0];
if(preg_match('/'.$table_prefix.'/', $old_table)) {
echo "Table $old_table already done<br/>\n";
continue;
}
$new_table = $table_prefix.$old_table;
echo "Renaming $old_table to $new_table<br/>\n";
$query = "RENAME TABLE `$old_table` TO `$new_table`";
mysql_query($query);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment