Skip to content

Instantly share code, notes, and snippets.

@careydayrit
Created October 9, 2019 18:29
Show Gist options
  • Save careydayrit/3a1b41014a16ae7ef04c4811ec646153 to your computer and use it in GitHub Desktop.
Save careydayrit/3a1b41014a16ae7ef04c4811ec646153 to your computer and use it in GitHub Desktop.
<h1>Pantheon MyISAM to InnoDB engine converter</h1>
<?php
/*
* Use this script ONLY if you are a Pantheon customer.
* ONLY RUN THIS SCRIPT IN DEV!
*/
$mysqli = @new mysqli($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME'], $_ENV['DB_PORT']);
if ($mysqli->connect_errno) {
echo "<h1>Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."</h1>\n";
die(1);
}
$results = $mysqli->query("show tables;");
if ($results===false or $mysqli->connect_errno) {
echo "<h1>MySQL error: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."</h1>\n";
die(2);
}
while ($row= $results->fetch_assoc())
{
$sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_pantheon']}'";
$thisTable = $mysqli->query($sql)->fetch_assoc();
if ($thisTable['Engine']==='MyISAM') {
$sql = "alter table " . $row['Tables_in_pantheon'] . " ENGINE = InnoDB;";
echo $row['Tables_in_pantheon'] . " is using the " . $thisTable['Engine'] . " Engine. <span class='red'>[ Changing ]</span> <br />\n";
$mysqli->query($sql);
} else {
echo $row['Tables_in_pantheon'] . ' is already using the ' . $thisTable['Engine'] . " Engine. <span class='green'>[ Ignoring ]</span> <br />\n";
}
};
die(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment