Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Multi-DB (Conversion Tool)
- Plugin URI: http://premium.wpmudev.org/project/Multiple-Databases
- Description:
- Author: Ron Dillehay - FanMail to rdillehay@hotmail.com (no tech support please) - Modified slightly by Andrew Billits (Incsub)
- Version: 2.9.2
- Author URI:
- Descriptiom:
- This script is to move blogs from a wordpress mu single database setup, to a wordpress mu multiple database setup using an MD5 hash to establish blog routing
- Use this script at your own risk. My test setup uses php 5, mysql 5, and wordpress mu 1.2.5a
- */
- //------------------------------------------------------------------------//
- //---Config---------------------------------------------------------------//
- //------------------------------------------------------------------------//
- ///DB Settings
- $dbname = "blogline_"; //This is your current database
- $blog_table_prefix = 'wp_'; //Prefix of your wpmu blog tables, most likely this won't need to be changed
- $newdb_prefix = 'blogline_wrdp1';
- //We need info to connect to the databases
- $dbhost = 'localhost';
- $dbuname = 'blogline_wrdp1';
- $dbpass = 'yourMySQLRootpass';
- //------------------------------------------------------------------------//
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Multiple Databases Conversion Tool</title>
- <head>
- <style type="text/css">
- table.stats
- {text-align: center; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif ; font-weight: normal;font-size: 12px;color: #fff;width: 750px;background-color: #666;border: 1px solid #555;border-collapse: collapse;border-spacing: 1px;}
- table.stats td
- {background-color: #CCC;color: #000;padding: 6px;text-align: left;border: 1px #fff solid;}
- table.stats td.head
- {background-color: #666;color: #fff;padding: 6px;text-align: center;border-bottom: 2px #fff solid;font-size: 12px;font-weight: bold;}
- </style>
- </head>
- <?php
- //Check to see if we are moving tables yet
- $tabletomove = 'copy';
- mysql_connect($dbhost, $dbuname, $dbpass) or die("Houston, we have a problem! <br />Database Error: ".mysql_error());
- for ( $counter = 5; $counter <= 9; $counter += 1) {
- $this_blog_new_db = $dbname.$counter;
- mysql_select_db($this_blog_new_db) or die("Houston, we have a problem! <br /><b> Looks like you need to create your new db's! If you're lucky, this link still works - <a href='http://calc.idtstudios.com/db.php'>click me</a> </b><br />Database Error: ".mysql_error());
- //Get our table list from the original db
- $sql = "SHOW TABLES FROM $this_blog_new_db";
- $result = mysql_query($sql);
- if (!$result) {
- echo "DB Error, could not list tables <br /> <b>Make sure you configure your original table in the dbname variable at the top of the script!</b><br />\n";
- echo 'MySQL Error: ' . mysql_error();
- exit;
- }
- /*echo "<table align='center' class='stats'><tr><td colspan='4' align='center'><br /><ol>
- <li>Tested on PHP 5 & MySQL 5</li>
- <li>Make sure all of your new db's exist (green text next to table name in db column below)</li>
- <li>In the status section, each table should show <i>not in new db (unless you've already run this script)</i></li>
- <li>To start the copy process <a href='reverse-blogs.php?table=copy'>click here</a> </li>
- <li>Be patient, depending on how many blogs you have, this could take a while</li>
- <li>Once completed, refresh this page by <a href='reverse-blogs.php'>clicking here</a></li>
- <li>Check to make sure that in the status section all tables say <i>table in new db</i></li>
- <li>Rejoice, I probably just saved you hours of your life!</li>
- <li>If this didn't work, don't blame me. Sometimes life is just like that..</li></ol>
- </td></tr><tr><td class='head' width='25%'>table name</td><td class='head' width='25%'>new db</td><td class='head' width='25%'>status</td></tr>";*/
- while ($row = mysql_fetch_row($result)) {
- //$db = mysql_connect($dbhost, $dbuname, $dbpass) or die("Houston, we have a problem! <br />Database Error: ".mysql_error());
- mysql_select_db($newdb_prefix) or die("Houston, we have a problem! <br /><b> Looks like you need to create your new db's! If you're lucky, this link still works - <a href='http://calc.idtstudios.com/db.php'>click me</a> </b><br />Database Error: ".mysql_error());
- //if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$row[0]."'"))) { $tabletest = "<font color='green'>table in new db</font>"; } else { $tabletest = "table not in new db"; }
- if ($tabletomove != "") {
- //This is where the heavy lifting is done - amazing only four lines of code can save so much time! Tested on php 5 - mysql 5
- $sql_table = "CREATE TABLE IF NOT EXISTS $row[0] LIKE $this_blog_new_db.$row[0]";
- $insert_info = "INSERT INTO $row[0] SELECT * FROM $this_blog_new_db.$row[0]";
- mysql_query($sql_table);
- mysql_query($insert_info);
- //mysql_free_result($sql_table);
- //mysql_free_result($insert_info);
- }
- //Close the db and report db status
- //echo "<tr><td>{$row[0]}</td><td>{$this_blog_new_db} <i>{$testpass}</i></td><td>{$tabletest}</td></tr>";
- } // end while
- } //end for
- mysql_close($db); $testpass = "<font color='green'> exists</font>";
- echo "</table>";
- //Clean up after ourselves
- echo "<center>Ignore any errors below this line</center>";
- echo "<center>================================================================================</center>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement