address of the mysql host * 'username' => mysql user * 'password' => password of the mysql user * 'database' => database name * ); */ $CONFIG = array( 'hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'test' ); // connect to database $conn = @mysqli_connect( $CONFIG['hostname'], $CONFIG['username'], $CONFIG['password'] ); if (!$conn) { die("FAILURE: ". mysql_connect_error($conn) ."\n"); } // get tables $sql = "SHOW TABLES FROM `". $CONFIG['database'] ."`"; $rstTables = runQuery($conn, $sql); // run check $tableCount = 0; $tablesOk = array(); $tablesFailed = array(); while( $row = getNextRow($rstTables) ) { foreach($row as $key => $table) { $tableCount++; $sql = "check table `". $CONFIG['database'] ."`.`". $table ."`"; $rstCheck = runQuery($conn, $sql); while( $rowCheck = getNextRow($rstCheck) ) { if ( $rowCheck['Msg_type'] == 'status' and $rowCheck['Msg_text'] == 'OK' ) { $tablesOk[ $table ] = $rowCheck; } else { $tablesFailed[ $table ] = $rowCheck; } } } } // close connection mysqli_close($conn); // print result if ( count($tablesFailed) == 0 ) { echo 'OK: '. $tableCount .' tables checked in database '. $CONFIG['database']; } else { echo 'FAILURE: '. $tableCount .' tables checked in database '. $CONFIG['database'] .', tables '; echo implode(', ', array_keys($tablesFailed)) .' failed'; } function runQuery($conn, $sql ) { $result = array(); $rst = @mysqli_query($conn, $sql); if (!$rst) { die("FAILURE: " . mysql_error() ."\n"); } return $rst; } function getNextRow( $rst ) { return ( mysqli_fetch_array($rst, MYSQLI_ASSOC ) ) ; } ?>