'; foreach ($_SESSION['debug'] as $q => $query_data) { // Fix the indentation.... $query_data['q'] = ltrim(str_replace("\r", '', $query_data['q']), "\n"); $query = explode("\n", $query_data['q']); $min_indent = 0; foreach ($query as $line) { preg_match('/^(\t*)/', $line, $temp); if (strlen($temp[0]) < $min_indent || $min_indent == 0) $min_indent = strlen($temp[0]); } foreach ($query as $l => $dummy) $query[$l] = substr($dummy, $min_indent); $query_data['q'] = implode("\n", $query); $is_select_query = substr(trim($query_data['q']), 0, 6) == 'SELECT'; if ($is_select_query) $select = $query_data['q']; elseif (preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+(SELECT .+)$~s', trim($query_data['q']), $matches) != 0) { $is_select_query = true; $select = $matches[1]; } elseif (preg_match('~^CREATE TEMPORARY TABLE .+?(SELECT .+)$~s', trim($query_data['q']), $matches) != 0) { $is_select_query = true; $select = $matches[1]; } echo '
', nl2br(str_replace("\t", '   ', htmlspecialchars($query_data['q']))), '
'; if (!empty($query_data['f']) && !empty($query_data['l'])) echo ' in ', $query_data['f'], ' line ', $query_data['l'], ', '; echo ' which took ', round($query_data['t'], 8), ' seconds.
'; // Explain the query. if ($query_id == $q && $is_select_query) { $result = db_query(" EXPLAIN " . $select, false, false); if ($result === false) { echo '
', mysql_error($db_connection), '
'; continue; } echo ' '; $row = mysql_fetch_assoc($result); echo ' '; mysql_data_seek($result, 0); while ($row = mysql_fetch_assoc($result)) { echo ' '; } mysql_free_result($result); echo '
' . implode(' ', array_keys($row)) . '
' . implode(' ', $row) . '
'; } } echo ' '; obExit(false); } ?>