";
// Only permit sql SELECT statements
if(!eregi("^select .*$", $query))
{
echo " Invalid SQL Query ";
echo "
$query
";
return;
}
opendb();
$tmpq = str_replace("\\", "", $query);
$endPos=$curPos+$linesPerPage;
$tcurpos = $curPos+$startapi;
$tendpos = $endPos+$startapi;
// set a limit if not already set
if(!stristr($query, "limit"))
$tmpq .= " LIMIT $tcurpos,$linesPerPage";
// execute the db query
$tstamp = time();
$result = mysql_query($tmpq);
$tstamp = time() - $tstamp;
if(debugging())
echo " QUERY TIME: $tstamp seconds
\n";
// query error!
if(!$result)
{
echo "$query
\n";
echo "A QUERY error occurred: ".mysql_error()."\n";
exit;
}
$numRows = mysql_num_rows($result);
$numCols = mysql_num_fields($result);
$curPage = $curPos/$linesPerPage;
$tmendpos = $curPos + $numRows;
$explain = "stdquery.php?query=".urlencode("EXPLAIN $tmpq");
echo html_br(2);
// set $debug to enable query debugging
if($debug || stristr($tmpq, "explain"))
{
$str = eregi_replace("(SELECT|EXPLAIN|DISTINCT|FROM|WHERE|AND".
"|OR |IS NULL|IS NOT NULL|LIMIT|ORDER BY".
"|GROUP BY)",
"
\\1
", $tmpq);
echo "
$str
\n";
}
echo html_echo("