Welcome to the Mysql Interactive Query System

MYHEAD; function show_form($user="uinf533", $server="bidu.lab", $dbase="inf533", $query="show tables" ){ global $myhead; $myform=<<
User: Password: Server: Database:

Enter your SQL command: 
 
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 ""; 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 ""; } print "
ColumnType Size Flags
$col_name[$i]$type[$i]$len[$i] $flags[$i]
"; print "

"; /* Printing results in one HTML table: */ print ''; print ""; for ($i=0; $i< $ncols; $i++){ print ""; } 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 ""; else print "\n"; $i++; } print "\n"; } print "
$col_name[$i]
$col_value$col_value
\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 ""; } ?>