can I remove zen_ prefix from all tables?
Hi i have zen cart version 1.3.9g I have been searching for a script or a fast way to remove the zen_ prefix because I am moving my site to a new server and the new db has zen_ as a prefix and my other site has no prefix does anyone know of a script to do this or a fast method besides manually changing them?
thanks
Re: removing zen_ prefix from all tables
nvm find a great script... here you go everyone works perfrect just add your info in it
PHP Code:
<?php
$db_server = "localhost"; // hostname MySQL server
$db_username = "username"; // username MySQL server
$db_password = "password"; // password MySQL server
$db_name = "database"; // database name
$pattern = "pattern_"; // search string
$new_pattern = "new_pattern_"; // replacement string,
// can be empty
// login to MySQL server
$link = mysql_connect( $db_server, $db_username, $db_password);
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
// list all tables in the database containing the search pattern
$sql = "SHOW TABLES FROM `" . $db_name . "`";
$sql .= " LIKE '%" . $pattern . "%'";
$result = mysql_query ( $sql, $link );
if (!$result)
{
die("Invalid query: " . mysql_error( $link ));
}
$renamed = 0;
$failed = 0;
while ( $row = mysql_fetch_array ($result) )
{
// rename every table by replacing the search pattern
// with a new pattern
$table_name = $row[0];
$new_table_name = str_replace ( $pattern, $new_pattern, $table_name);
$sql = "RENAME TABLE `" . $db_name . "`.`" . $table_name . "`";
$sql .= " TO `" . $db_name . "`.`" . $new_table_name . "`";
$result_rename = mysql_query ( $sql, $link );
if ($result_rename)
{
echo "Table `" . $table_name . "` renamed to :`";
echo $new_table_name . "`.\n";
$renamed++;
}
else
{
// notify when the renaming failed and show reason why
echo "Renaming of table `" . $table_name . "` has failed: ";
echo mysql_error( $link ) . "\n";
$failed++;
}
}
echo $renamed . " tables were renamed, " . $failed . " failed.\n";
// close connection to MySQL server
mysql_close( $link );
?>
Re: removing zen_ prefix from all tables
I too have a database with the zen_ prefix that I need to remove. This script looks like what I need. Excuse a couple of dumb questions.
[FONT=Courier New]<?php
$db_server = "localhost"; [/FONT][FONT=Courier New]// hostname MySQL server
$db_username = "username"; [/FONT][FONT=Courier New]// username MySQL server
$db_password = "password"; [/FONT][FONT=Courier New]// password MySQL server
$db_name = "database"; [/FONT][FONT=Courier New]// database name
$pattern = "pattern_"; [/FONT][FONT=Courier New]// search string
$new_pattern = "new_pattern_"; [/FONT][FONT=Courier New]// replacement string,
// can be empty [/FONT]
Is all I need to do is change localhost, username, password and database?
is "pattern_" supposed to be changed to zen_ and "new_pattern" changed to ""
Thanks a bunch for your help
Re: removing zen_ prefix from all tables
Yes just replace that db info with your and change the pattern_ to whatever you like to remove. And the new_ pattern with whatver you want to replace it with ex. Pattern_ could be zen_ then new_pattern could be "" and that would remove zen _ from the db
Re: removing zen_ prefix from all tables
after I change these items, do I just go to admin/tools/ and past it into the run sql patches?
Thanks
Re: can I remove zen_ prefix from all tables?
No this is a Php script so name the file something.php and then place it in the folder of your web server that is the base folder. Then go to your websites.com/something.php and it should run and tell you all of the tables modified. Make sure you give the file executable privileges and then once your done remove it from your server .
Re: Database prefix change
I just had success with this code.
My db prefix was "zen" and I just changed it to "zen_"
Re: Database prefix change
One thing: taking out zen also renamed the authorizenet table by taking out its "zen", so the payments area didn't come up in admin. I googled and quickly learned how to rename a table.