adodb

Print evaluated query string using ADODB/PHP

Snippet

After a parameterized querystring has been evaluated, but before the query has been run, print out the query string, using ADODB PHP library.

<?php
 
/*
 * include the ADODB library
 */
include('adodb.inc.php');
 
/*
 * Make a new connection to DB
 */
$mydb = &ADONewConnection('access');     
$mydb->PConnect('northwind');  
 
/*
 * filter input
 */
$shipto = $conn->qstr("John's Old Shoppe");
 
/*
 * generate SQL
 */
$sql = "insert into orders (customerID,EmployeeID,OrderDate,ShipName) ";
$sql .= "values ('ANATR',2,".$mydb->FormatDate(time()).",?)";
 
/*
 *
 *
 * PRINT THE SQL BEFORE EXECUTING THE QUERY
 *
 *
 */
$mydb->debug = true;
 
if ($mydb->Execute($sql, $shipto) === false) print 'error inserting';
 
?>

Enable PHP ADODB handling

Snippet

By default, PHP's ADODB library will not give full error messages on pconnect, or route to an error handler. The error handler has to be enabled.

<?php
 
// pass any error messages triggered to error handler
error_reporting(E_ALL); 
 
include('adodb-errorhandler.inc.php');
include('adodb.inc.php');
 
// suppress error messages for the connection
ini_set("display_errors", "0");
try {
  $mydb = &ADONewConnection('mysql');
  $mydb->PConnect('dbhost','dbuser','dbpass','dbname');
} catch (exception $e) {
  // unable to connect to the DB (usually too many connections), redirect away                                                                                            
  header('Location: /error.html');
  exit();
}