Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement