Advertisement
MarkdeScande

reverse-blogs_atof.txt

Feb 15th, 2012
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  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 = 'copy';
  51. mysql_connect($dbhost, $dbuname, $dbpass) or die("Houston, we have a problem! <br />Database Error: ".mysql_error());
  52. for ( $counter = 10; $counter <= 15; $counter += 1) {
  53. $this_blog_new_db = $dbname.$counter;
  54. if ( $counter == 10 ) {
  55. $this_blog_new_db = $dbname."a";
  56. }
  57. if ( $counter == 11 ) {
  58. $this_blog_new_db = $dbname."b";
  59. }
  60. if ( $counter == 12 ) {
  61. $this_blog_new_db = $dbname."c";
  62. }
  63. if ( $counter == 13 ) {
  64. $this_blog_new_db = $dbname."d";
  65. }
  66. if ( $counter == 14 ) {
  67. $this_blog_new_db = $dbname."e";
  68. }
  69. if ( $counter == 15 ) {
  70. $this_blog_new_db = $dbname."f";
  71. }
  72. 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());
  73.  
  74. //Get our table list from the original db
  75. $sql = "SHOW TABLES FROM $this_blog_new_db";
  76. $result = mysql_query($sql);
  77.  
  78. if (!$result) {
  79. 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";
  80. echo 'MySQL Error: ' . mysql_error();
  81. exit;
  82. }
  83.  
  84. /*echo "<table align='center' class='stats'><tr><td colspan='4' align='center'><br /><ol>
  85. <li>Tested on PHP 5 & MySQL 5</li>
  86. <li>Make sure all of your new db's exist (green text next to table name in db column below)</li>
  87. <li>In the status section, each table should show <i>not in new db (unless you've already run this script)</i></li>
  88. <li>To start the copy process <a href='reverse-blogs.php?table=copy'>click here</a> </li>
  89. <li>Be patient, depending on how many blogs you have, this could take a while</li>
  90. <li>Once completed, refresh this page by <a href='reverse-blogs.php'>clicking here</a></li>
  91. <li>Check to make sure that in the status section all tables say <i>table in new db</i></li>
  92. <li>Rejoice, I probably just saved you hours of your life!</li>
  93. <li>If this didn't work, don't blame me. Sometimes life is just like that..</li></ol>
  94. </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>";*/
  95.  
  96. while ($row = mysql_fetch_row($result)) {
  97.  
  98. //$db = mysql_connect($dbhost, $dbuname, $dbpass) or die("Houston, we have a problem! <br />Database Error: ".mysql_error());
  99. 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());
  100. //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"; }
  101.  
  102.  
  103. if ($tabletomove != "") {
  104. //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
  105. $sql_table = "CREATE TABLE IF NOT EXISTS $row[0] LIKE $this_blog_new_db.$row[0]";
  106. $insert_info = "INSERT INTO $row[0] SELECT * FROM $this_blog_new_db.$row[0]";
  107. mysql_query($sql_table);
  108. mysql_query($insert_info);
  109. //mysql_free_result($sql_table);
  110. //mysql_free_result($insert_info);
  111. }
  112. //Close the db and report db status
  113.  
  114. //echo "<tr><td>{$row[0]}</td><td>{$this_blog_new_db} <i>{$testpass}</i></td><td>{$tabletest}</td></tr>";
  115. } // end while
  116. } //end for
  117. mysql_close($db); $testpass = "<font color='green'>&nbsp;exists</font>";
  118. echo "</table>";
  119.  
  120. //Clean up after ourselves
  121. echo "<center>Ignore any errors below this line</center>";
  122. echo "<center>================================================================================</center>";
  123.  
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement