<? links_of("All table contents",$quey_all,$limits) ?>
</ul>
</p>
- <h2>Custom Query</h2>
+ <h2>Custom Query - Simple Interface</h2>
<form action="composequery.php" method="get">
<table>
<tr>
</tr>
</table>
</form>
+<h2>Custom Query - raw SQL</h2>
+<form action="showquery.php" method="get">
+<table>
+</tr>
+<? query("describe bench","printer"); ?>
+</tr>
+<tr><td>
+<input type="text" size="50" name="query" value="select * from bench;"/></td>
+</tr>
+<tr><td>
+<input type="submit" value="Submit" class="button" /></td>
+</tr>
+</table>
+</form>
+
</body>
</html>
}
}
+function prettify($s,$name) {
+ if (preg_match("/^[0-9]{12}$/",$s)) {
+ $year = substr($s,0,4);
+ $month = substr($s,4,2);
+ $day = substr($s,6,2);
+ $hour = substr($s,8,2);
+ $minute = substr($s,10,2);
+ return $day . "/" . $month . "/" . $year . " " . $hour . ":" . $minute;
+ } else if (preg_match("/time/",$name)){
+ $min = floor($s / 6000);
+ $sec = floor(($s - $min * 6000) / 100);
+ $cents = $s % 100;
+ return $min . "m" . $sec . "." . $cents . "s";
+ } else
+ return rtrim($s);
+}
+
+
+function printer($q){
+ global $i;
+ echo "<tr>";
+ if ( $i == 0) {
+ foreach( $q as $name => $txt) {
+ echo "<th>$name</th>";
+ }
+ }
+ echo "</tr>\n";
+ if ( $i%2 == 0)
+ echo "<tr class=\"even\">";
+ else
+ echo "<tr class=\"odd\">";
+ foreach( $q as $name => $txt) {
+ echo "<td>" . prettify($txt,$name) . "</td>";
+ }
+ echo "</tr>\n";
+ $i++;
+}
+
+
function query($q,$f) {
$db = mysql_pconnect("localhost","helm");
mysql_select_db("matita");
+ if (!preg_match("/^(select|describe)[^\n;]*;?$/i",$q)) {
+ echo "Query not allowed!";
+ return;
+ }
$rc = mysql_query($q,$db);
if(!$rc) {
die("Query failed: " . mysql_error());
$qs = array();
foreach($nqs as $v){
$x = explode("@@@",$v);
- $qs[$x[0]] = $x[1];
+ if ($x[1] == NULL) {
+ $qs["Unnamed"] = $x[0];
+ } else {
+ $qs[$x[0]] = mysql_escape_string($x[1]);
+ }
}
-function prettify($s,$name) {
- if (preg_match("/^[0-9]{12}$/",$s)) {
- $year = substr($s,0,4);
- $month = substr($s,4,2);
- $day = substr($s,6,2);
- $hour = substr($s,8,2);
- $minute = substr($s,10,2);
- return $day . "/" . $month . "/" . $year . " " . $hour . ":" . $minute;
- } else if ($name == "sum_time" || $name == "sum_timeuser" || $name == "time" || $name == "time_user" || $name == "timeuser"){
- $min = floor($s / 6000);
- $sec = floor(($s - $min * 6000) / 100);
- $cents = $s % 100;
- return $min . "m" . $sec . "." . $cents . "s";
- } else
- return $s;
-}
-
-function printer($q){
- global $i;
- echo "<tr>";
- if ( $i == 0) {
- foreach( $q as $name => $txt) {
- echo "<th>$name</th>";
- }
- }
- echo "</tr>\n";
- if ( $i%2 == 0)
- echo "<tr class=\"even\">";
- else
- echo "<tr class=\"odd\">";
- foreach( $q as $name => $txt) {
- echo "<td>" . prettify($txt,$name) . "</td>";
- }
- echo "</tr>\n";
- $i++;
-}
-
?>
<html>
<head>
<? foreach( $qs as $name => $q) { $i=0;?>
<h2><? echo $name; ?></h2>
<p>
- <tt><? print $q; ?></tt>
+ <tt><? echo $q; ?></tt>
</p>
<table border=1>
<? query($q,"printer"); ?>