PHP Batch Change database table prefix implementation method _php instance

Source: Internet
Author: User

By following this method, easy to handle, the code below, useful to the top.

Copy Code code as follows:

<?php
        $database = " DatabaseName ";        //Database name
        $ user = "root";                       //database user name
        $pwd = "pwd";                          //Database password
        $replace = ' pre_ ';                      //replacement prefix
        $seach = ' pre1_ ';                     //prefix to replace
        $db =mysql_connect ("localhost", "$user", "$pwd") or Die ("Connection Database failed:". Mysql_error () );         //Connection database

        $ tables = Mysql_list_tables ("$database");       
         while ($name = Mysql_fetch_array ($tables)) {

                 $table = Str_replace ($seach, $replace, $name [' 0 ']);

                mysql_query ( "Rename table $name [0] to $table");
       }





If you add a prefix you just need to change a little bit


Copy Code code as follows:

$table = Str_replace ($seach, $replace, $name [' 0 ']);
$table = $replace. $name [' 0 '];



is OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.