Posted By

beneberle on 08/07/10


Tagged

mysql php security joomla


Versions (?)

Change Default Joomla Database Table Prefix


 / Published in: PHP
 

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

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.

  1. <?php
  2. $new_prefix = 'new_';
  3. require_once 'configuration.php';
  4. $config = new JConfig;
  5. $con = mysql_connect($config->host, $config->user, $config->password);
  6. if(!is_resource($con)) die('Error connecting to db');
  7. $test = mysql_select_db($config->db, $con);
  8. if($test===false) die('Error connecting to db');
  9. $prefix = $config->dbprefix;
  10. $sql = "show tables where `Tables_in_{$config->db}` like '{$prefix}%'";
  11. $res = mysql_query($sql);
  12. while($row = mysql_fetch_array($res))
  13. {
  14. $old = $row[0];
  15. $new = $new_prefix . substr($old, 4);
  16. $temp = mysql_query("RENAME TABLE `$old` TO `$new`");
  17. if($temp === false) die(mysql_error());
  18. }
  19. echo "OK";
  20. ?>

Report this snippet  

You need to login to post a comment.