Skip to content

Instantly share code, notes, and snippets.

@sbarrat

sbarrat/alterEngine.php Secret

Last active Dec 25, 2015
Embed
What would you like to do?
Alter all tables of a Database width Engine INNODB
<?php
/**
* Created by Ruben Lacasa Mas
* User: Ruben Lacasa Mas <ruben@rubenlacasa.es>
* Date: 18/10/13
* Time: 12:18
*/
$dbhost = 'hostname';
$dbname = 'dbname';
$dbuser = 'dbuser';
$dbpass = 'dbpassword';
$dsn = 'mysql:dbname='.$dbname.';host='.$dbhost;
try {
$dbh = new PDO($dsn, $dbuser, $dbpass);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = "SHOW TABLES";
$query = $dbh->prepare($sql);
$query->execute();
$tables = $query->fetchAll(PDO::FETCH_CLASS);
foreach ($tables as $table) {
$sqlAlter = "ALTER TABLE ".$table->Tables_in_dbname." ENGINE=INNODB;";
$dbh->exec($sqlAlter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.