| ADOdb Library for PHP Manual | ||
|---|---|---|
| Prev | Inserting | Next |
Insert a row to the Orders table containing dates and strings that need to be quoted before they can be accepted by the database, eg: the single-quote in the word John's.
<?php
include('adodb.inc.php'); #
load code common to ADOdb
$conn = &ADONewConnection('access'); #
create a connection
$conn->PConnect('northwind'); #
connect to MS-Access, northwind dsn
$shipto = $conn->qstr("John's
Old Shoppe");
$sql = "insert
into orders (customerID,EmployeeID,OrderDate,ShipName) ";
$sql .= "values
('ANATR',2,".$conn->DBDate(time()).",$shipto)";
if ($conn->Execute($sql) === false) {
print 'error
inserting: '.$conn->ErrorMsg().'<BR>';
}
?>
In this example, we see the advanced date and quote handling facilities of ADOdb. The unix timestamp (which is a long integer) is appropriately formated for Access with DBDate(), and the right escape character is used for quoting the John's Old Shoppe, which is John''s Old Shoppe and not PHP's default John's Old Shoppe with qstr().
Observe the error-handling of the Execute statement. False is returned by Execute()
if an error occured. The error message for the last error that occurred is displayed
in ErrorMsg(). Note: php_track_errors
might have to be enabled for error messages to be saved.
| Prev | Home | Next |
| Advanced Select with Field Objects | Up | Debugging |