MYFORM;
echo $myhead, $myform;
} //end of show_form definition
function getmutime(){
list($usec, $sec)= explode(" ", microtime());
return ((float)$sec + (float)$usec);
}
if(!isset($_POST[password])) {
show_form();
return;
} // will come here only if form was filled
$_POST[query]= trim($_POST[query]);
if(empty($_POST[user]) || empty($_POST[password]) || empty($_POST[server]) || empty($_POST[dbase]) || empty($_POST[query])){
echo 'You did not fill in all required fields, please try again:
';
show_form($_POST[user],$_POST[server],$_POST[dbase],$_POST[query]);
}else {
echo $myhead;
$_POST[server]= $_POST[server].".ic.unicamp.br";
$link = mysql_connect($_POST[server],$_POST[user],$_POST[password])
or die("Could not connect");
mysql_select_db($_POST[dbase]) or die("Could not select database");
$_POST[query]=stripslashes($_POST[query]);
print "Your SQL command:\n\n$_POST[query]
";
/* Performing SQL query */
$start= getmutime();
$result = mysql_query($_POST[query])
or die("Error ".mysql_errno().": ".mysql_error());
if (!preg_match("/update|delete|insert|create|drop/i",$_POST[query])){
print "Results:";
$ncols= mysql_num_fields($result);
$nrows = mysql_num_rows($result);
print '
';
print "";
print "Column | Type | Size |
Flags |
";
for ($i=0; $i< $ncols; $i++){
$meta= mysql_fetch_field($result);
$numfield[$i]=$meta->numeric;
$not_null[$i]= $meta->not_null;
$col_name[$i]=mysql_field_name($result,$i);
$type[$i]=mysql_field_type($result,$i);
$len[$i]=mysql_field_len($result,$i);
$flags[$i]=mysql_field_flags($result,$i);
print "$col_name[$i] | $type[$i] | $len[$i] |
$flags[$i] |
";
}
print "
";
print "";
/* Printing results in one HTML table: */
print '
';
print "";
for ($i=0; $i< $ncols; $i++){
print "$col_name[$i] | ";
}
print "
";
while ($line = mysql_fetch_row($result)) {
print "\n";
$i=0;
foreach ($line as $col_value) {
if ($col_value =="")
if($not_null[$i]) $col_value=" ";
else $col_value="NULL";
if($numfield[$i])
print "$col_value | ";
else
print "$col_value | \n";
$i++;
}
print "
\n";
}
print "
\n";
$nrows= mysql_num_rows($result);
$time= number_format(getmutime() - $start,1);
print "$nrows rows returned by your query in $time secs";
mysql_free_result($result); /* Free resultset */
}else{
$nrows= mysql_affected_rows();
print "
$nrows row(s) affected by your update/insert/delete command";
}
mysql_close($link); /* Close connection */
echo "