Created
April 3, 2016 14:58
-
-
Save MarkGavalda/8b127703e60247c2a6871fe4489e7d0f to your computer and use it in GitHub Desktop.
PHP conversion script from MyISAM to InnoDB for a WordPress site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once( 'wp-config.php' ); | |
$db = array(); | |
$db['host'] = DB_HOST; | |
$db['user'] = DB_USER; | |
$db['password'] = DB_PASSWORD; | |
$db['database'] = DB_NAME; | |
$db['connectString'] = $db['host']; | |
$mysqli = @new mysqli($db['connectString'], $db['user'], $db['password'], $db['database']); | |
if ($mysqli->connect_errno) { | |
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."\n"; | |
die(1); | |
} | |
$results = $mysqli->query("show tables;"); | |
if ($results===false or $mysqli->connect_errno) { | |
echo "MySQL error: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error ."\n"; | |
die(2); | |
} | |
while ($row= $results->fetch_assoc()) { | |
$sql = "SHOW TABLE STATUS WHERE Name = '{$row['Tables_in_' . $db['database']]}'"; | |
$thisTable = $mysqli->query($sql)->fetch_assoc(); | |
if ($thisTable['Engine']==='MyISAM') { | |
$sql = "alter table " . $row['Tables_in_' . $db['database']]. " ENGINE = InnoDB;"; | |
echo "Changing {$row['Tables_in_' . $db['database']]} from {$thisTable['Engine']} to InnoDB.\n"; | |
$mysqli->query($sql); | |
} else { | |
echo $row['Tables_in_' . $db['database']] . ' is of the Engine Type ' . $thisTable['Engine'] . ".\n"; | |
echo "Not changing to InnoDB.\n\n"; | |
} | |
} | |
die(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment