change MyISAM to InnoDB

Public

Pantheon MyISAM to InnoDB engine converter

Get raw version
php
  1. <style>
  2. .green { color: green; font-family: monospace;}
  3. .red { color: red; font-family: monospace;}
  4. </style>
  5. <h1>Pantheon MyISAM to InnoDB engine converter</h1>
  6.  
  7. <?php
  8. /*
  9.  * Use this script ONLY if you are a Pantheon customer.
  10.  * ONLY RUN THIS SCRIPT IN DEV!
  11.  */
  12. $mysqli = @new mysqli($_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
  13.  
  14. if ($mysqli->connect_errno) {
  15. echo "<h1>Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."</h1>\n";
  16. die(1);
  17. }
  18.  
  19. $results = $mysqli->query("show tables;");
  20.  
  21. if ($results===false or $mysqli->connect_errno) {
  22. echo "<h1>MySQL error: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."</h1>\n";
  23. die(2);
  24. }
  25.  
  26. while ($row= $results->fetch_assoc())
  27. {
  28. $sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_pantheon']}'";
  29. $thisTable = $mysqli->query($sql)->fetch_assoc();
  30.  
  31. if ($thisTable['Engine']==='MyISAM') {
  32. $sql = "alter table " . $row['Tables_in_pantheon'] . " ENGINE = InnoDB;";
  33. echo $row['Tables_in_pantheon'] . " is using the " . $thisTable['Engine'] . " Engine. <span class='red'>[ Changing ]</span> <br />\n";
  34. $mysqli->query($sql);
  35. } else {
  36. echo $row['Tables_in_pantheon'] . ' is already using the ' . $thisTable['Engine'] . " Engine. <span class='green'>[ Ignoring ]</span> <br />\n";
  37. }
  38. };
  39.  
  40. die(0);