XC. PDO Functions

Introduction

Warning

This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

Installation

PDO is currently available as a PECL extension from http://pecl.php.net/package/pdo. Ensure you have installed the CGI version of PHP and that the pear and phpize scripts are available in your current path.

Run the following command to download, build, and install the latest stable version of PDO:
pear install pdo

Windows users can download the extension DLL php_pdo.dll as part of the PECL collection binaries from http://www.php.net/downloads.php.

The pear command automatically installs the PDO module into your PHP extensions directory. To enable the PDO extension on Linux or Unix operating systems, you must add the following line to php.ini:
extension=pdo.so
To enable the PDO extension on Windows operating systems, you must add the following line to php.ini:
extension=php_pdo.dll

PDO Drivers

The following drivers currently implement the PDO interface:

Driver nameSupported databases
PDO_FIREBIRDFirebird/Interbase 6
PDO_MYSQLMySQL 3.x/4.0
PDO_OCIOracle Call Interface
PDO_ODBCODBC v3 (IBM DB2 and unixODBC)
PDO_PGSQLPostgreSQL
PDO_SQLITESQLite 3.x

Predefined Classes

PDO

Represents a connection between PHP and a database server.

Constructor

  • PDO - constructs a new PDO object

Methods

  • beginTransaction - begins a transaction

  • commit - commits a transaction

  • exec - issues an SQL statement

  • errorCode - retrieves an error code, if any, from the database

  • errorInfo - retrieves an array of error information, if any, from the database

  • lastInsertId - retrieves the value of the last row that was inserted into a table

  • prepare - prepares an SQL statement for execution

  • rollBack - roll back a transaction

  • setAttribute - sets a database connection attribute

PDOStatement

Represents a prepared statement and, after the statement is executed, an associated result set.

Methods

  • bindColumn - binds a PHP variable to an output column in a result set

  • bindParam - binds a PHP variable to a parameter in the prepared statement

  • errorCode - retrieves an error code, if any, from the statement

  • errorInfo - retrieves an array of error information, if any, from the statement

  • execute - executes a prepared statement

  • fetch - fetches a row from a result set

  • fetchAll - fetches an array containing all of the rows from a result set

  • fetchSingle - returns the data from the first column in a result set

  • rowCount - returns the number of rows that were affected by the execution of an SQL statement

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

PDO_PARAM_NULL (integer)

PDO_PARAM_INT (integer)

PDO_PARAM_STR (integer)

PDO_PARAM_LOB (integer)

PDO_PARAM_STMT (integer)

PDO_FETCH_LAZY (integer)

PDO_FETCH_ASSOC (integer)

PDO_FETCH_NUM (integer)

PDO_FETCH_BOTH (integer)

PDO_FETCH_OBJ (integer)

PDO_ATTR_AUTOCOMMIT (integer)

PDO_ATTR_SCROLL (integer)

PDO_ATTR_PREFETCH (integer)

PDO_ATTR_TIMEOUT (integer)

PDO_ATTR_ERRMODE (integer)

PDO_ATTR_SERVER_VERSION (integer)

PDO_ATTR_CLIENT_VERSION (integer)

PDO_ATTR_SERVER_INFO (integer)

PDO_ATTR_CONNECTION_STATUS (integer)

PDO_ATTR_CASE (integer)

PDO_ERRMODE_SILENT (integer)

PDO_ERRMODE_WARNING (integer)

PDO_ERRMODE_EXCEPTION (integer)

PDO_CASE_NATURAL (integer)

PDO_CASE_LOWER (integer)

PDO_CASE_UPPER (integer)

PDO_ERR_NONE (integer)

PDO_ERR_CANT_MAP (integer)

PDO_ERR_SYNTAX (integer)

PDO_ERR_CONSTRAINT (integer)

PDO_ERR_NOT_FOUND (integer)

PDO_ERR_ALREADY_EXISTS (integer)

PDO_ERR_NOT_IMPLEMENTED (integer)

PDO_ERR_MISMATCH (integer)

PDO_ERR_TRUNCATED (integer)

PDO_ERR_DISCONNECTED (integer)

Table of Contents
PDO::beginTransaction --  Initiates a transaction
PDO::commit --  Commits a transaction
PDO::__construct --  Creates a PDO instance to represent a connection to a database
PDO::errorCode --  Fetch the error code associated with the last operation on the database handle
PDO::errorInfo --  Fetch extended error information associated with the last operation on the database handle
PDO::exec --  Execute a query that does not return a row set, returning the number of affected rows
PDO::lastInsertId --  Returns the number id of rows that we affected by the last call to PDO::exec()
PDO::prepare --  Prepares a statement for execution and returns a statement object
PDO::rollBack --  Rolls back a transaction
PDO::setAttribute --  Set an attribute
PDOStatement::bindColumn --  Bind a column to a PHP variable
PDOStatement::bindParam --  Binds a parameter to a the specified variable name
PDOStatement::errorCode --  Fetch the error code associated with the last operation on the statement handle
PDOStatement::errorInfo --  Fetch an array of error information associated with the last operation on the statement handle
PDOStatement::execute --  Executes a prepared statement
PDOStatement::fetch --  Fetches the next row from a result set
PDOStatement::fetchAll --  Returns an array containing all of the result set rows
PDOStatement::fetchSingle --  Returns the first column in the next row of a result set
PDOStatement::rowCount --  Returns the number of rows affected by the last SQL statement