Skip to content

Instantly share code, notes, and snippets.

@sbarrat
Last active December 25, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbarrat/a27d4311f4928672544f to your computer and use it in GitHub Desktop.
Save sbarrat/a27d4311f4928672544f to your computer and use it in GitHub Desktop.
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