Return to Snippet

Revision: 30099
at August 7, 2010 11:52 by beneberle

Initial Code
$new_prefix = 'new_';
require_once 'configuration.php';
$config = new JConfig;
$con = mysql_connect($config->host, $config->user, $config->password);
if(!is_resource($con)) die('Error connecting to db');
$test = mysql_select_db($config->db, $con);
if($test===false) die('Error connecting to db');
$prefix = $config->dbprefix;
$sql = "show tables where `Tables_in_{$config->db}` like '{$prefix}%'";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res))
    $old = $row[0];
    $new = $new_prefix . substr($old, 4);
    $temp = mysql_query("RENAME TABLE `$old` TO `$new`");
    if($temp === false) die(mysql_error());
echo "OK";

Initial URL

Initial Description
Substitute new_ placeholder in the second line with your new prefix.  Run it: and wait until it responds with an OK, usually after a couple of seconds.  Delete the rename.php script.  Edit the configuration.php file and find the line starting with var $dbprefix. It should look like this:  var $dbprefix = \'jos_\';  Replace the old jos_ prefix with new prefix, i.e. the one used in the second line of your rename.php script.

Initial Title
Change Default Joomla Database Table Prefix

Initial Tags
mysql, php, security, joomla

Initial Language