Last active
July 22, 2016 07:05
-
-
Save kroatoanweb/8f18670dd79199e15093c39a86eae185 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Configuración de la aplicación | |
* Idealmente en un fichero aparte | |
*/ | |
$dsn = 'mysql:dbname=nuestrabasededatos;host=127.0.0.1'; | |
$user = 'dbuser'; | |
$password = 'dbpass'; | |
try { | |
$dbh = new PDO($dsn, $user, $password); | |
//Obtenemos la lista de tablas a optimizar | |
$sth = $dbh->prepare("SHOW TABLES"); | |
$sth->execute(); | |
$tables = $sth->fetchAll(PDO::FETCH_COLUMN); | |
//Recorremos la lista optimizando cada una de las tablas | |
if (count($tables) > 0 && is_array($tables)) { | |
foreach ($tables as $table) { | |
$sth = $dbh->prepare("OPTIMIZE TABLE `{$table}`"); | |
$sth->execute(); | |
} | |
} | |
} catch (PDOException $e) { | |
die('Fallo de conexión: ' . $e->getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment