MySQL
  Home arrow MySQL arrow Page 3 - MySQL Table Prefix Changer Tool in PHP
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

MySQL Table Prefix Changer Tool in PHP
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 13
    2008-01-02

    Table of Contents:
  • MySQL Table Prefix Changer Tool in PHP
  • Constructing the tool
  • Editing your current database tables
  • Putting the database back together

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    MySQL Table Prefix Changer Tool in PHP - Editing your current database tables


    (Page 3 of 4 )

    Now it’s time to get into the meat and potatoes of this thing. We need to break into our else block and construct the code that should be executed in the event that POST data is found.

    <?php

    } else {

     

    $mysql_db = $_REQUEST['d'];

    $mysql_user = $_REQUEST['u'];

    $mysql_pass = $_REQUEST['p'];

    $table_prefix = $_REQUEST['n'];

    We’re going to begin by grabbing the POST data set back by our form and pushing that into a few variables for later use.

    // Open MySQL link

    $link = mysql_connect('localhost', $mysql_user, $mysql_pass);

    if (!$link) {

        die('Could not connect: ' . mysql_error());

    }

    echo 'Connected successfully<br><br>';

    Next, we make a MySQL connection using the information provided by the user form submission.

    // Select database and grab table list

    mysql_select_db($mysql_db, $link) or die ("Database not found.");

    $tables = mysql_list_tables($mysql_db);

    Then, we connect to the specified database and get a list of its table names.  The mysql_list_tables() function provides a quick mechanism for this.

    // Pull table names into an array and replace prefixes

    $i = 0;

    while ($i < mysql_num_rows($tables)) {

       $table_name = mysql_tablename($tables, $i);

       $table_array[$i] = $table_name;

       $i++;

    }

    Now, we want to process the results of our table list query. We’re going to parse each table name and put that information into a string array. This will make processing them much more efficient. A While loop serves our needs perfectly.

    // Pull table names into another array after replacing prefixes

    foreach ($table_array as $key => $value) {

       $table_names[$key] = replace_prefix($value, $table_prefix);

    }

    Finally, we are going to take each element from this array and build a new array after changing the prefix. We will need to create the replace_prefix() function that makes this all possible.

    More MySQL Articles
    More By Nilpo


       · From the article:"In some cases, they are even able to append them as POST data...
       · Query strings are in fact GET data. Thank you for your correction.
     

       

    MYSQL ARTICLES

    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway