select_db(DB); } $explain = 1; while (strlen($query)) { if (!$offset && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) { $delimiter = $match[1]; $query = substr($query, strlen($match[0])); } else { preg_match('(' . preg_quote($delimiter) . '|[\'`"]|/\\*|-- |#|$)', $query, $match, PREG_OFFSET_CAPTURE, $offset); // should always match $found = $match[0][0]; $offset = $match[0][1] + strlen($found); if (!$found && $fp && !feof($fp)) { $query .= fread($fp, 1e5); } else { if (!$found && !strlen(rtrim($query))) { break; } if (!$found || $found == $delimiter) { // end of a query $empty = false; $q = substr($query, 0, $match[0][1]); echo "
" . shorten_utf8(trim($q), 1000) . "\n"; ob_flush(); flush(); // can take a long time - show the running query $start = explode(" ", microtime()); // microtime(true) is available since PHP 5 //! don't allow changing of character_set_results, convert encoding of displayed query if (!$connection->multi_query($q)) { echo "
" . lang('Error in query') . ": " . h($connection->error) . "\n"; if ($_POST["error_stops"]) { break; } } else { $end = explode(" ", microtime()); echo "
" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . "
\n"; do { $result = $connection->store_result(); if (is_object($result)) { select($result, $connection2); if ($connection2 && preg_match("~^($space|\\()*SELECT\\b~isU", $q)) { $id = "explain-$explain"; echo "" . ($result->num_rows ? lang('%d row(s)', $result->num_rows) . ", " : ""); echo "EXPLAIN\n"; echo "
" . upload_error($query) . "\n"; } } ?>