<?php // adodbsql.php Celio Guimaraes Aug 2004 include('adodb/adodb.inc.php'); //include('adodb/tohtml.inc.php'); $ADODB_COUNTRECS=false; $now= date('d-m-Y H:i:s', time()); $myhead=<<<MYHEAD <HTML><HEAD><TITLE>ADODB Generic Query Processor</TITLE></HEAD> <BODY style="background:Silver" onLoad="document.myform.password.focus()"> <h2 align="center">Welcome to the Interactive SQL Query System</h2> MYHEAD; echo $myhead; $host="bidu.lab.ic.unicamp.br"; $sgbd="mysql"; //or oracle, mysql, firebird $user="scott"; $password="tiger"; $server="test"; // or winestore echo "<b>SGBD: $sgbd User: $user Database: $server $now</b><p>"; switch ($sgbd){ case 'postgres': $host=''; break; } $conn = &ADONewConnection($sgbd) or die("ADDONewConnection($sgbd) failed"); $conn->autoRollback = true; $conn->Connect($host,$user,$password,$server) or die ("Could not connect.."); $query="show tables"; print "<b>Your SQL command:</b><p>"; print "<pre><blockquote>$query</blockquote></pre>"; if ($query=="show tables"){ echo "<h3>Tables in Database $server:</h3>"; $meta= $conn->MetaTables(); }//if /* Performing SQL query */ $stmt= $conn->Execute($query) or die($conn->ErrorMsg()); $ncols= $stmt->FieldCount(); $nrows = 0; print "<b>Results:</b><p>"; for ($i=0; $i< $ncols; $i++){ $fld= $stmt->FetchField($i); $col_name[$i]= $fld->name; $type[$i]= $stmt->MetaType($fld->type); $len[$i]= $fld->max_length; } /* Printing results in one HTML table: */ print '<table border="1" cellpadding="4">'; print "<tr>"; for ($i=0; $i< $ncols; $i++){ print "<th align= left>$col_name[$i]</th>"; } print "</tr>\n"; print "<tr>"; while( ($r= $stmt->FetchRow())){ $nrows++; for ($i=0; $i< $ncols; $i++){ $col_value= $r[$i]; if ($col_value =="") $col_value=" "; if($type[$i]=='N' or $type[$i]=='I' or $type[$i]=='R' or $type[$i]=='X') print "<td align=right>$col_value</td>"; else print "<td align =left>$col_value</td>\n"; } //for print "</tr>\n"; } // while print "</table>\n"; print "<p>$nrows rows returned by your SQL command"; print "</body></html>"; ?>