Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
SpaceMonkey
Worker
Worker



Joined: Apr 30, 2005
Posts: 170

PostPosted: Mon Aug 08, 2005 1:06 am Reply with quote

I want to change the table prefix on my phpnuke tables in the mysql database. (I hope that made sense) How do I do this without losing all the data from my site?

I guess I just have to change it in the config.php file and change it on each thingy (sorry, I dont' know what I'm talking about) using phpmyadmin.. Does this sound right? I just have to change each prefix idividually and change the config file..

Will that interfere with nukesentinel?

TIA
 
View user's profile Send private message Visit poster's website
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Mon Aug 08, 2005 5:26 am Reply with quote

Code:
<?php

/***********************************************************************************/
/* Name:    renametables.php                                                       */
/* Author:  Gaylen Fraley aka Raven                                                */
/* Support: http://ravenphpscripts.com                                             */
/* Date:    2005-08-08                                                             */
/* Purpose: Renames all tables from current $user_prefix to $prefixNew.            */
/* Usage:   Place this script in your nuke root folder. To see what the change will*/
/*          look like, set $testRun to TRUE; Once you're satisfied that the changes*/
/*          are correct, set $testRun to FALSE; and re-execute the script.         */
/* License: Free                                                                   */
/* Warranty:None.  Proceed at your own risk.                                       */
/***********************************************************************************/
$prefixNew    = "nuke1";
$testRun      = FALSE;

/***********************************************************************************/
/* DO NOT CHANGE ANYTHING PAST THIS LINE UNLESS YOU REALLY KNOW WHAT YOU'RE DOING! */
/***********************************************************************************/
require('config.php');
$prefixOld    = $user_prefix;
$prefixOldLen = strlen($prefixOld);
$prefixNewLen = strlen($prefixNew);
mysql_connect($dbhost, $dbuname, $dbpass);
$result = mysql_list_tables($dbname);
$num_rows = mysql_num_rows($result);
for ($i = 0; $i < $num_rows; $i++) {
   if (!(substr(mysql_tablename($result, $i),0,$prefixOldLen)==$prefixOld)) continue;
   $sql = 'RENAME TABLE '.mysql_tablename($result, $i).' TO '.$prefixNew.substr(mysql_tablename($result, $i), $prefixOldLen).';';
   if (!$testRun) {
      @mysql_query($sql);
      if (mysql_error()) echo('MySQL said: '.mysql_error())."<br />";
      else echo 'Table '.mysql_tablename($result, $i).' Renamed To '.$prefixNew.substr(mysql_tablename($result, $i), $prefixOldLen)."<br />";
   }
   else echo $sql."<br />";
}
mysql_free_result($result);
?>
 
View user's profile Send private message
SpaceMonkey







PostPosted: Tue Aug 09, 2005 12:07 am Reply with quote

Is this an old script you had lying around, Raven?

Thanks a million!
 
Raven







PostPosted: Tue Aug 09, 2005 12:23 am Reply with quote

Nope. I wrote it and the other one in response to your requests RavensScripts
 
SpaceMonkey







PostPosted: Sat Aug 13, 2005 1:32 am Reply with quote

Thanks for this one Raven. It's a very useful script and it worked perfectly.. Now I have a nice safe and secret prefix.. Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©