PDO FunctionsPDO
&reftitle.intro;
&warn.experimental;
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.
&reftitle.install;
Windows
Follow the same steps to install and enable the PDO drivers of your
choice.
Windows users can download the extension DLL php_pdo.dll
as part of the PECL collection binaries from
&url.php.downloads;.
To enable the PDO extension on Windows operating systems, you must
add the following line to &php.ini;:
Linux and UNIX
Due to a bug in the pear installer you should install
the PDO package manually using the following steps:
Follow the same steps to install and enable the PDO drivers of your
choice.
Download the PDO package to your local machine:
Determine your PHP bin directory. If your
PHP 5 CLI binary lives at /usr/local/php5/bin/php
then the bin dir is /usr/local/php5/bin.
Set your path so that your PHP bin directory
is at the front:
Manually build and install the PDO extension:
> /usr/local/php5/lib/php.ini
]]>
PDO Drivers
The following drivers currently implement the PDO interface:
Driver nameSupported databasesPDO_DBLIBFreeTDS / Microsoft SQL Server / SybasePDO_FIREBIRDFirebird/Interbase 6PDO_MYSQLMySQL 3.x/4.0PDO_OCIOracle Call InterfacePDO_ODBCODBC v3 (IBM DB2 and unixODBC)PDO_PGSQLPostgreSQLPDO_SQLITESQLite 3.x
&reftitle.classes;
PDO
Represents a connection between PHP and a database server.
&reftitle.constructor;
PDO - constructs a new PDO
object
&reftitle.methods;
beginTransaction
- begins a transactioncommit - commits a
transactionexec - issues an SQL
statement and returns the number of affected rowserrorCode -
retrieves an error code, if any, from the databaseerrorInfo -
retrieves an array of error information, if any, from the
databasegetAttribute -
retrieves a database connection attributelastInsertId -
retrieves the value of the last row that was inserted into a
tableprepare - prepares
an SQL statement for executionquery - issues an SQL
statement and returns a result setquote - returns a
quoted version of a string for use in SQL statementsrollBack - roll
back a transactionsetAttribute -
sets a database connection attributePDOStatementRepresents a prepared statement and, after the statement is
executed, an associated result set.
&reftitle.methods;
bindColumn - binds a
PHP variable to an output column in a result setbindParam - binds a
PHP variable to a parameter in the prepared statementcolumnCount -
returns the number of columns in the result seterrorCode -
retrieves an error code, if any, from the statementerrorInfo -
retrieves an array of error information, if any, from the statementexecute - executes a
prepared statementfetch - fetches a
row from a result setfetchAll - fetches an
array containing all of the rows from a result setfetchSingle - returns
the data from the first column in a result setgetAttribute -
retrieves a PDOStatement attributegetColumnMeta -
retrieves metadata for a column in the result setrowCount - returns the
number of rows that were affected by the execution of an SQL statementsetAttribute -
sets a PDOStatement attributesetFetchMode -
sets the fetch mode for a PDOStatement
&reference.pdo.constants;
&reference.pdo.functions;