LazyRecord\TableStatus\MySQLTableStatus::queryDetails PHP 메소드

queryDetails() 공개 메소드

public queryDetails ( array $tables )
$tables array
    public function queryDetails(array $tables)
    {
        $dbName = $this->connection->query('SELECT database();')->fetchColumn();
        /*
        SELECT 
            CONCAT(table_schema, '.', table_name),
            CONCAT(ROUND(table_rows / 1000000, 2), 'M') AS rows,
            CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') AS data,
            CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') AS idx,
            CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') AS total_size,
            ROUND(index_length / data_length, 2) AS idxfrac
            FROM information_schema.TABLES 
            WHERE table_schema = 'bossnet' ORDER  BY data_length + index_length DESC LIMIT  10;
        */
        $query = $this->createStatusDetailQuery();
        $query->where()->equal('table_schema', $dbName);
        if (count($tables)) {
            $query->where()->in('table_name', $tables);
        }
        $args = new ArgumentArray();
        $sql = $query->toSql($this->driver, $args);
        $stm = $this->connection->prepare($sql);
        $stm->execute($args->toArray());
        return $stm->fetchAll(PDO::FETCH_ASSOC);
    }

Usage Example

예제 #1
0
 public function execute()
 {
     $tables = func_get_args();
     $configLoader = $this->getConfigLoader(true);
     $dataSource = $this->getCurrentDataSourceId();
     $conn = $this->getCurrentConnection();
     $driver = $this->getCurrentQueryDriver();
     if ($driver instanceof PDOMySQLDriver) {
         $status = new MySQLTableStatus($conn, $driver);
         $this->logger->info('Table Status:');
         $rows = $status->queryDetails($tables);
         $this->displayRows($rows);
         $this->logger->newline();
         $this->logger->info('Table Status Summary:');
         $rows = $status->querySummary($tables);
         $this->displayRows($rows);
     } else {
         $this->logger->error('Driver not supported.');
     }
 }