You are here

MySqlHandler.php in DB Maintenance 8

MySqlHandler class.

File

src/Module/Db/DbServer/MySql/MySqlHandler.php
View source
<?php

/**
 * @file
 * MySqlHandler class.
 */
namespace Drupal\db_maintenance\Module\Db\DbServer\MySql;

use Drupal\db_maintenance\Module\Db\DbServer\DbServerHandlerInterface;

/**
 * MySqlHandler class.
 */
class MySqlHandler implements DbServerHandlerInterface {

  /**
   * Returns list of tables in the active database.
   */
  public function listTables() {
    $result = \Drupal::database()
      ->query("SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'", array(), array(
      'fetch' => \PDO::FETCH_ASSOC,
    ));
    return $result;
  }

  /**
   * Optimizes table in the active database.
   */
  public function optimizeTable($table_name) {
    try {
      \Drupal::database()
        ->query("OPTIMIZE TABLE {$table_name}")
        ->execute();
    } catch (\Exception $e) {
      watchdog_exception('type', $e);
    }
  }

}

Classes

Namesort descending Description
MySqlHandler MySqlHandler class.