SHARE
TWEET

reverse-blogs_global.txt

MarkdeScande Feb 15th, 2012 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Plugin Name: Multi-DB (Conversion Tool)
  4. Plugin URI: http://premium.wpmudev.org/project/Multiple-Databases
  5. Description:
  6. Author: Ron Dillehay - FanMail to rdillehay@hotmail.com (no tech support please) - Modified slightly by Andrew Billits (Incsub)
  7. Version: 2.9.2
  8. Author URI:
  9. Descriptiom:
  10. 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
  11. Use this script at your own risk.  My test setup uses php 5, mysql 5, and wordpress mu 1.2.5a
  12. */
  13.  
  14. //------------------------------------------------------------------------//
  15. //---Config---------------------------------------------------------------//
  16. //------------------------------------------------------------------------//
  17.  
  18. ///DB Settings
  19. $dbname = "blogline_";  //This is your current database
  20. $blog_table_prefix = 'wp_';  //Prefix of your wpmu blog tables, most likely this won't need to be changed
  21. $newdb_prefix = 'blogline_wrdp1';
  22.  
  23. //We need info to connect to the databases
  24. $dbhost = 'localhost';
  25. $dbuname = 'blogline_wrdp1';
  26. $dbpass = 'yourMySQLRootpass';
  27.  
  28. //------------------------------------------------------------------------//
  29. ?>
  30.  
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33. <head>
  34.  
  35. <title>Multiple Databases Conversion Tool</title>
  36. <head>
  37. <style type="text/css">
  38. table.stats
  39. {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;}
  40. table.stats td
  41. {background-color: #CCC;color: #000;padding: 6px;text-align: left;border: 1px #fff solid;}
  42. table.stats td.head
  43. {background-color: #666;color: #fff;padding: 6px;text-align: center;border-bottom: 2px #fff solid;font-size: 12px;font-weight: bold;}
  44. </style>
  45. </head>
  46.  
  47. <?php
  48.  
  49. //Check to see if we are moving tables yet
  50. //$tabletomove = $_REQUEST["table"];
  51. $tabletomove = 'copy';
  52. mysql_connect($dbhost, $dbuname, $dbpass) or die("Houston, we have a problem! <br />Database Error: ".mysql_error());
  53. $this_blog_new_db = $dbname."global";  
  54. 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());
  55.  
  56. //Get our table list from the original db
  57. $sql = "SHOW TABLES FROM $this_blog_new_db";
  58. $result = mysql_query($sql);
  59.  
  60. if (!$result) {
  61.         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";
  62.         echo 'MySQL Error: ' . mysql_error();
  63.         exit;
  64. }
  65.  
  66. /*echo "<table align='center' class='stats'><tr><td colspan='4' align='center'><br /><ol>
  67.         <li>Tested on PHP 5 & MySQL 5</li>
  68.         <li>Make sure all of your new db's exist (green text next to table name in db column below)</li>
  69.         <li>In the status section, each table should show <i>not in new db (unless you've already run this script)</i></li>
  70.         <li>To start the copy process <a href='reverse-blogs3.php?table=copy'>click here</a> </li>
  71.         <li>Be patient, depending on how many blogs you have, this could take a while</li>
  72.         <li>Once completed, refresh this page by <a href='reverse-blogs3.php'>clicking here</a></li>
  73.         <li>Check to make sure that in the status section all tables say <i>table in new db</i></li>
  74.         <li>Rejoice, I probably just saved you hours of your life!</li>
  75.         <li>If this didn't work, don't blame me.  Sometimes life is just like that..</li></ol>
  76.         </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>";
  77. */
  78. while ($row = mysql_fetch_row($result)) {      
  79.        
  80.         //$db = mysql_connect($dbhost, $dbuname, $dbpass) or die("Houston, we have a problem! <br />Database Error: ".mysql_error());
  81.         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());
  82.         //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"; }
  83.  
  84.        
  85.         if ($tabletomove != "") {
  86.                 //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
  87.                 $sql_table = "CREATE TABLE IF NOT EXISTS $row[0] LIKE $this_blog_new_db.$row[0]";
  88.                 $insert_info = "INSERT INTO $row[0] SELECT * FROM $this_blog_new_db.$row[0]";
  89.                 mysql_query($sql_table);
  90.                 mysql_query($insert_info);
  91.                 //mysql_free_result($sql_table);
  92.                 //mysql_free_result($insert_info);
  93.         }
  94.         //Close the db and report db status
  95.        
  96.         //echo "<tr><td>{$row[0]}</td><td>{$this_blog_new_db} <i>{$testpass}</i></td><td>{$tabletest}</td></tr>";
  97. } // end while    
  98. /*mysql_close($db);
  99. $testpass = "<font color='green'>&nbsp;exists</font>";
  100. */
  101. echo "</table>";
  102.  
  103. //Clean up after ourselves
  104. echo "<center>Ignore any errors below this line</center>";
  105. echo "<center>================================================================================</center>";
  106.  
  107. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top