require_once 'init.php'; $return = array(); $label = $_REQUEST['label']; $database = $_REQUEST['db']; $table = $_REQUEST['table']; $return['label'] = $label; $return['database'] = $database; $return['table'] = $table; $return['column'] = $col; $return['title'] = "{$database}.{$table}"; $host = $explainhosts[$label]; Database::connect(null, $host['user'], $host['password'], null, null, 'pdo', array('dsn' => $host['dsn']), $label); Database::find($label)->query('USE ' . Database::escapeField($database)); list($tmp, $return['create']) = Database::find($label)->query_row('SHOW CREATE TABLE ' . Database::escapeField($table)); $return['create'] = SqlParser::html($return['create']); $desc = Database::find($label)->query_list_assoc('DESC ' . Database::escapeField($table)); $return['desc'] = '<table><thead><tr>'; foreach (array_keys($desc[0]) as $key) { $return['desc'] .= '<th>' . $key . '</th>'; } $return['desc'] .= '</tr></thead><tbody>'; foreach ($desc as $row) { $return['desc'] .= '<tr>'; foreach ($row as $key => $val) { $return['desc'] .= '<td>' . ifnull($val, 'NULL') . '</td>'; } $return['desc'] .= '</tr>'; } $return['desc'] .= '</tbody></table>'; unset($desc);
$primaryKey .= ", {$field} "; } } $offset = 0; if (isset($_REQUEST['offset']) && $_REQUEST['offset'] > 0) { $offset = intval($_REQUEST['offset']); } $res = Database::find('review')->query('SELECT review.sample ' . $primaryKey . ' FROM ' . Database::escapeField($reviewhost['history_table']) . ' AS review WHERE review.checksum = ? ORDER BY review.ts_max DESC LIMIT 1 OFFSET ' . $offset, $_REQUEST['checksum']); $row = $res->fetch_assoc(); $return['sample'] = $row['sample']; foreach ($reviewhost['history_table_primary'] as $field) { $return['primary'][$field] = $row[$field]; } $return['offset'] = $offset; } else { $return['sample'] = Database::find('review')->query_col('SELECT review.sample FROM ' . Database::escapeField($reviewhost['review_table']) . ' AS review WHERE review.checksum = ?', $_REQUEST['checksum']); } if (strlen($return['sample'])) { $return['sample'] = SqlParser::html($return['sample']); } header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); echo json_encode($return);