<?php 
require "config.php"
//для отладки надо видеть ошибки
ini_set("display_errors",true);
//true в magic_quotes убьёт любой sql-запрос, переданный через POST
ini_set("magic_quotes_gpc",false);
//если текст запроса не передан, устанавливаем его по умолчанию
$sqlpost=@$_POST["sql"];
$sqlpost=($sqlpost)?$sqlpost:"1";
//переменные из configbase.php
print "$doctype $meta";
$title=substr($sqlpost,0,60);
if (
1==$sqlpost) {
 
$code=implode("",file(__FILE__));
 print 
"<title>Исходный код файла \"{$host}{$uri}\"</title>";
 
highlight_string($code);
 exit;
}
print 
"<title>Результаты запроса \"{$title}\"</title>";
?>

<style type="text/css">
td, tr {vertical-align:top;}
td {border:1px solid #777; padding:.5em;}
table {border-collapse:collapse;}
table, ul {margin:auto;}
</style>

<?php
print "<p>Выполнить запрос sql</p>
<form id='sqlpost' method='post'>
<input name='sql' style='width:30em;' id='sql' value=\"
$sqlpost\">
</p><input type='submit'></p>
</form>"
;

mysql_connect("localhost","{$bdprefix}dntest","password") or exit(mysql_error());
mysql_query("use `$bd`") or exit(mysql_error());;
mysql_query("set names cp1251");

sqlres($sqlpost);

function 
sqlres($value) {
 
$r=mysql_query($value) or exit(mysql_error());
 
$n=mysql_num_rows ($r);
 if (!
$n) exit("В запросе \"$value\" нет строк.");
 print 
"<p>Запрос \"$value\",</p><p>всего строк: <b>$n</b></p>";
 
$num=0;
 
$head="<table><tr><th>N</th>";
 while (
$line mysql_fetch_assoc($r)) {
  
$num++;
  
$str="<tr><td class=\"num\">$num</td>";
  foreach (
$line as $key=>$val) {
   
$val=preg_replace("/(\r?\n)+/i","<br>",$val);
   
$str.="<td>$val</td>";
   if (
1==$num) {
    
$head.="<th>$key</th>";
   }
   else 
$head="";
  }
  
$head.="$str</tr>\n";
  print 
$head;
 }
 print 
"</table>";
}

?>