ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:userguide_index

This is an old revision of the document!


This page is under reconstruction

User Guide

List Of Tutorials

Basic Tasks

Database AbstractionUsing basic ADOdb commands to read data from and write back to the database
Data Dictionary BasicsHow to obtain information about database fields, columns and tables
Keys,Fields & Field ObjectsUnderstanding how to work with the most detailed level of data provided by ADOdb

Advanced Tasks

Transactions Understanding Transaction scope, and how to start, stop and roll back transactions
Multi Database Connections Controlling connections and transactional scoping in multiple databases simultaneously
Creating & Extending Drivers Adding new functionality and changing the behaviour of existing drivers

Additional Documentation

Example 3: Inserting

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.

include('adodb.inc.php');    # load code common to ADOdb
$conn = adoONewConnection('access');        # create a connection
$conn->pConnect('northwind');   # connect to MS-Access, northwind dsn

/*
* Inserting a string containing quote characters 
* may cause a statement to fail if not pre-processed
*/
$shipto = $conn->qstr("John's Old Shoppe");
$orderDate = $conn->dbDate(time());
 
$sql = "insert into orders (customerID,EmployeeID,OrderDate,ShipName) ";
$sql .= "values ('ANATR',2,".$orderDate.",$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 formatted for Access with dBDate(). Note that the date field should not be quoted. If required by the database, the field will be automatically quoted.

The correct 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 by using qStr().

Observe the error-handling of the Execute statement. False is returned by Execute() if an error occurred. 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.

v5/userguide/userguide_index.1458356699.txt.gz · Last modified: 2017/04/21 11:39 (external edit)