Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Configuración de la aplicación
* Idealmente en un fichero aparte
$dsn = 'mysql:dbname=nuestrabasededatos;host=';
$user = 'dbuser';
$password = 'dbpass';
try {
$dbh = new PDO($dsn, $user, $password);
//Obtenemos la lista de tablas a optimizar
$sth = $dbh->prepare("SHOW TABLES");
$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}`");
} 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
You can’t perform that action at this time.