Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Configuración de la aplicación
  5. * Idealmente en un fichero aparte
  6. */
  7. $dsn = 'mysql:dbname=nuestrabasededatos;host=127.0.0.1';
  8. $user = 'dbuser';
  9. $password = 'dbpass';
  10.  
  11. try {
  12. $dbh = new PDO($dsn, $user, $password);
  13.  
  14. //Obtenemos la lista de tablas a optimizar
  15. $sth = $dbh->prepare("SHOW TABLES");
  16. $sth->execute();
  17.  
  18. $tables = $sth->fetchAll(PDO::FETCH_COLUMN);
  19.  
  20. //Recorremos la lista optimizando cada una de las tablas
  21. if (count($tables) > 0 && is_array($tables)) {
  22. foreach ($tables as $table) {
  23. $sth = $dbh->prepare("OPTIMIZE TABLE `{$table}`");
  24. $sth->execute();
  25. }
  26. }
  27. } catch (PDOException $e) {
  28. die('Fallo de conexión: ' . $e->getMessage());
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement