Zen Cart Logo
Forums / General Questions / can I remove zen_ prefix from all tables?

can I remove zen_ prefix from all tables?

Views: 2,294

Results 1 to 8 of 8
22 Feb 2012, 9:48 PM
#1
warroyo90 avatar

warroyo90

New Zenner

Join Date:
Jan 2012
Posts:
59
Plugin Contributions:
0

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

22 Feb 2012, 10:20 PM
#2
warroyo90 avatar

warroyo90

New Zenner

Join Date:
Jan 2012
Posts:
59
Plugin Contributions:
0

Re: can I remove zen_ prefix from all tables?

nvm find a great script... here you go everyone works perfrect just add your info in it

<?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 );  
?>  
12 May 2012, 10:28 PM
#3
2004g35 avatar

2004g35

Zen Follower

Join Date:
Jan 2005
Location:
Winter Haven, FL
Posts:
156
Plugin Contributions:
0

Re: can I remove 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.

<?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


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

12 May 2012, 10:43 PM
#4
warroyo90 avatar

warroyo90

New Zenner

Join Date:
Jan 2012
Posts:
59
Plugin Contributions:
0

Re: can I remove 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

12 May 2012, 10:47 PM
#5
2004g35 avatar

2004g35

Zen Follower

Join Date:
Jan 2005
Location:
Winter Haven, FL
Posts:
156
Plugin Contributions:
0

Re: can I remove 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

13 May 2012, 3:55 PM
#6
warroyo90 avatar

warroyo90

New Zenner

Join Date:
Jan 2012
Posts:
59
Plugin Contributions:
0

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 .

26 Jul 2012, 10:59 PM
#7
sph avatar

sph

Totally Zenned

Join Date:
Jan 2006
Posts:
1,556
Plugin Contributions:
0

Re: can I remove zen_ prefix from all tables?

I just had success with this code.

My db prefix was "zen" and I just changed it to "zen_"

27 Jul 2012, 8:24 PM
#8
sph avatar

sph

Totally Zenned

Join Date:
Jan 2006
Posts:
1,556
Plugin Contributions:
0

Re: can I remove zen_ prefix from all tables?

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.