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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
MYSQL

MySQL Table Prefix Changer Tool in PHP
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 22
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek