Return to Snippet

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


Initial Code
<?php
$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());
    mysql_free_result($temp);
}
mysql_free_result($res);
mysql_close($con);
echo "OK";
?>

Initial URL
http://magazine.joomla.org/topics/item/108-the-prefix-has-nothing-to-do-with-telephony

Initial Description
Substitute new_ placeholder in the second line with your new prefix.  Run it: http://www.yoursite.com/rename.php 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
PHP