Steps:
- Take a database backup.
- Create a File Named "filename.php" and placed at root directory.
- Paste the above Script in it.
- before run the file if $dryrun=true; it mins only check the rename process or $dryrun=false; it mins rename the table.
- All tables will be renamed.
- go to app/etc/local.xml <table_prefix><![CDATA[prefix]]></table_prefix>
- you're done.
<?php
$database_host = "";
$database_user = "";
$database_password = "";
$magento_database = "";
$table_prefix = "ex_";
$dryrun = true; // change to false when you want to commit changes
$link = mysqli_connect($database_host, $database_user, $database_password, $magento_database);
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SHOW TABLES";
$result = mysqli_query($link,$query) or die('### Error cannot connect to DB');
if ($dryrun) { echo "### No changes made, just testing <br />"; }
while($row = mysqli_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`";
mysqli_query($link,$query);
echo " -> DONE <br />";
} else { echo " -> Just checking <br />"; }
} else {
echo "Nothing to rename: " . $old_table . "<br />";
}
}
}
?>
Thanks, Nice post it makes my day.
ReplyDelete