pearqry.php
<html>
<head>
<title>ODBTP PEAR DB Query</title>
</head>
<body>
<?php
require( "DB.php" );
$dsn = 'odbtp://myuid:mypwd@mydbhost/mydb';
$dbh = DB::connect( $dsn );
if( PEAR::isError( $dbh ) ) {
echo "Error message: " . $dbh->getMessage() . "<br>";
echo "Detailed error description: " . $dbh->getDebugInfo() . "<br>";
die;
}
$res = $dbh->query( $_REQUEST['query'] );
if( PEAR::isError( $res ) ) {
echo "Error message: " . $res->getMessage() . "<br>";
echo "Detailed error description: " . $res->getDebugInfo() . "<br>";
die;
}
do {
if( !($cols = $res->numCols()) ) continue;
echo $res->numRows() . " rows<p>";
$colinfo = $res->tableInfo();
if( PEAR::isError( $colinfo ) ) {
echo "Error message: " . $colinfo->getMessage() . "<br>";
echo "Detailed error description: " . $colinfo->getDebugInfo() . "<br>";
die;
}
echo "<table cellpadding=2 cellspacing=0 border=1>\n";
echo "<tr>";
echo "<td> <b>Table</b> </td>";
echo "<td> <b>Name</b> </td>";
echo "<td> <b>Type</b> </td>";
echo "<td> <b>Length</b> </td>";
echo "<td> <b>Flags</b> </td>";
echo "</tr>";
for( $i = 0; $i < $cols; $i++ ) {
echo "<tr>";
echo "<td> ". $colinfo[$i]['table'] . " </td>";
echo "<td> ". $colinfo[$i]['name'] . " </td>";
echo "<td> ". $colinfo[$i]['type'] . " </td>";
echo "<td> ". $colinfo[$i]['len'] . " </td>";
echo "<td> ". $colinfo[$i]['flags'] . " </td>";
echo "</tr>";
}
echo "</table><p>";
echo "<table cellpadding=2 cellspacing=0 border=1>\n";
echo "<tr>";
for( $col = 0; $col < $cols; $col++ ) {
echo "<td><nobr> " . $colinfo[$col]['name'] . " </nobr></td>";
}
echo "</tr>\n";
while( $row = $res->fetchRow() ) {
echo "<tr>";
for( $col = 0; $col < $cols; $col++ ) {
if( is_null( $row[$col] ) ) $row[$col] = "NULL";
echo "<td><nobr> $row[$col] </nobr></td>";
}
echo "</tr>\n";
}
echo "</table><p>\n";
}
while( $res->nextResult() );
$dbh->disconnect();
?>
</body>
</html>