Pages

Wednesday, December 19, 2012

Changing Wordpress DB all tables prefix - PHP code snippet

The following code will change the Wordpress  table prefix.
We need to make some corrections also as mentioned below:

<?php
$host='localhost';
$user='root';
$pass='';
$dbase = 'wordpress';

$db = mysqli_connect($host,$user, $pass, $dbase);

$allTables = $db->query('show tables');

while( $row = mysqli_fetch_array($allTables) ):
    $table = $row[0];
    $tSchema = $db->query('RENAME TABLE `wordpress`.`'.$table.'` TO `wordpress`.`'.str_replace('wp_', 'newprefix_', $table).'` ' );
endwhile;   
?>

The `wp_user_roles` need to be `newprefix_user_roles` of wp_options table

 and

`wp_capabilities` to `newprefix_capabilities` of wp_usermeta table.


No comments :

Post a Comment