|
|
 |
XCIX. PDO Functions
| 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.
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
/downloads.php or a more
recent version from a PHP 5 PECL
Snapshot.
To enable the PDO extension on Windows operating systems, you must
add the following line to php.ini:
Next, choose the other DB specific DLL files and either use
dl() to load them at runtime, or enable them in
php.ini below pdo_pdo.dll. For example:
extension=php_pdo.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll |
These DLL's should exist in the systems
extension_dir.
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:
bash$ wget http://pecl.php.net/get/PDO |
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:
export PATH="/usr/local/php5/bin:$PATH" |
Manually build and install the PDO extension:
bash$ tar xzf PDO-0.2.tgz
bash$ cd PDO-0.2
bash$ phpize
bash$ ./configure
bash$ make
bash$ sudo -s
bash# make install
bash# echo extension=pdo.so >> /usr/local/php5/lib/php.ini |
The following drivers currently implement the PDO interface:
Represents a connection between PHP and a database server.
beginTransaction
- begins a transaction
commit
- commits a transaction
exec
- issues an SQL statement and returns the number of affected rows
errorCode
- retrieves an error code, if any, from the database
errorInfo
- retrieves an array of error information, if any, from the
database
getAttribute
- retrieves a database connection attribute
lastInsertId
- retrieves the value of the last row that was inserted into a table
prepare
- prepares an SQL statement for execution
query
- issues an SQL statement and returns a result set
quote
- returns a quoted version of a string for use in SQL statements
rollBack
- roll back a transaction
setAttribute
- sets a database connection attribute
Represents a prepared statement and, after the statement is executed, an
associated result set.
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
columnCount
- returns the number of columns in the result set
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
getAttribute
- retrieves a PDOStatement attribute
getColumnMeta
- retrieves metadata for a column in the result set
nextRowset
- retrieves the next rowset (result set)
rowCount
- returns the number of rows that were affected by the execution of
an SQL statement
setAttribute
- sets a PDOStatement attribute
setFetchMode
- sets the fetch mode for a PDOStatement
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)
Represents the SQL NULL data type.
- PDO_PARAM_INT
(integer)
Represents the SQL INTEGER data type.
- PDO_PARAM_STR
(integer)
Represents the SQL CHAR, VARCHAR, or other string data type.
- PDO_PARAM_LOB
(integer)
Represents the SQL large object data type.
- PDO_PARAM_STMT
(integer)
- PDO_PARAM_INPUT_OUTPUT
(integer)
Specifies that the parameter is an INOUT parameter for a stored
procedure. You must bitwise-OR this value with an explicit
PDO_PARAM_* data type.
- PDO_FETCH_LAZY
(integer)
Specifies that the fetch method shall return each row as an object with
variable names that correspond to the column names returned in the result
set. PDO_FETCH_LAZY creates the object variable names as they are accessed.
- PDO_FETCH_ASSOC
(integer)
Specifies that the fetch method shall return each row as an array indexed
by column name as returned in the corresponding result set.
- PDO_FETCH_NUM
(integer)
Specifies that the fetch method shall return each row as an array indexed
by column number as returned in the corresponding result set, starting at
column 0.
- PDO_FETCH_BOTH
(integer)
Specifies that the fetch method shall return each row as an array indexed
by both column name and number as returned in the corresponding result set,
starting at column 0.
- PDO_FETCH_OBJ
(integer)
Specifies that the fetch method shall return each row as an object with
property names that correspond to the column names returned in the result
set.
- PDO_FETCH_BOUND
(integer)
Specifies that the fetch method shall return TRUE and assign the values of
the columns in the result set to the PHP variables to which they were
bound with the PDOStatement::bindParam() or
PDOStatement::bindColumn() methods.
- PDO_FETCH_COLUMN
(integer)
Specifies that the fetch method shall return only a single requested
column from the next row in the result set.
- PDO_FETCH_CLASS
(integer)
Specifies that the fetch method shall return a new instance of the
requested class, mapping the columns to named properties in the class.
- PDO_FETCH_INTO
(integer)
Specifies that the fetch method shall update an existing instance of the
requested class, mapping the columns to named properties in the class.
- PDO_FETCH_FUNC
(integer)
- PDO_FETCH_GROUP
(integer)
- PDO_FETCH_UNIQUE
(integer)
- PDO_FETCH_CLASSTYPE
(integer)
- PDO_ATTR_AUTOCOMMIT
(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)
Force column names to a specific case specified by the PDO_CASE_*
constants.
- PDO_ATTR_CURSOR_NAME
(integer)
- PDO_ATTR_CURSOR
(integer)
- PDO_ATTR_ORACLE_NULLS
(integer)
- PDO_ATTR_PERSISTENT
(integer)
- PDO_ERRMODE_SILENT
(integer)
- PDO_ERRMODE_WARNING
(integer)
- PDO_ERRMODE_EXCEPTION
(integer)
- PDO_CASE_NATURAL
(integer)
Leave column names as returned by the database driver.
- PDO_CASE_LOWER
(integer)
Force column names to lower case.
- PDO_CASE_UPPER
(integer)
Force column names to upper case.
- PDO_FETCH_ORI_NEXT
(integer)
Fetch the next row in the result set. Valid only for scrollable cursors.
- PDO_FETCH_ORI_PRIOR
(integer)
Fetch the previous row in the result set. Valid only for scrollable
cursors.
- PDO_FETCH_ORI_FIRST
(integer)
Fetch the first row in the result set. Valid only for scrollable cursors.
- PDO_FETCH_ORI_LAST
(integer)
Fetch the last row in the result set. Valid only for scrollable cursors.
- PDO_FETCH_ORI_ABS
(integer)
Fetch the requested row by row number from the result set. Valid only
for scrollable cursors.
- PDO_FETCH_ORI_REL
(integer)
Fetch the requested row by relative position from the current position
of the cursor in the result set. Valid only for scrollable cursors.
- PDO_CURSOR_FWDONLY
(integer)
Create a PDOStatement object with a forward-only cursor. This may improve
the performance of your application but restricts your PDOStatement object
to fetching one row at a time from the result set in a forward direction.
- PDO_CURSOR_SCROLL
(integer)
Create a PDOStatement object with a scrollable cursor. Pass the
PDO_FETCH_ORI_* constants to control the rows fetched from the result set.
- 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)
- PDO_ERR_NO_PERM
(integer)
- PDO_ERR_NONE
(string)
Corresponds to SQLSTATE '00000', meaning that the SQL statement was
successfully issued with no errors or warnings.
User Contributed Notes
PDO Functions
ng4rrjanbiah at rediffmail dot com
16-Mar-2005 01:53
Some useful links on PDO:
1. PDO Wiki ( http://wiki.cc/php/PDO )
2. Introducing PHP Data Objects ( http://netevil.org/downloads/Introducing-PDO.ppt ), [226 KB], Wez Furlong, 2004-09-24
3. The PHP 5 Data Object (PDO) Abstraction Layer and Oracle ( http://www.oracle.com/technology/pub/articles/php_experts/ otn_pdo_oracle5.html ), [60.85 KB], Wez Furlong, 2004-07-28
4. PDO - Why it should not be part of core PHP! ( http://www.akbkhome.com/blog.php/View/55/ ), Critical review, [38.63 KB], Alan Knowles, 2004-10-22
HTH,
R. Rajesh Jeba Anbiah
Jeremy (php AT jermy dotnet)
01-Mar-2005 06:30
Just in case it isn't clear for linux users - the instructions above only tell you how to compile the base PDO package, but not any of the drivers which are needed to allow you to actually use any paticular database.
All the drivers are on PECL - see http://pecl.php.net/package-search.php?pkg_name=PDO_ - and they are downloaded and installed in an identical manner to the PDO package (which needs to be installed first, and appear before any driver-specific 'extension=' lines).
For example, to enable PostgreSQL support, download the package from http://pecl.php.net/get/PDO_PGSQL and run the commands as above: untar the file, run 'phpize && ./configure && make && make install' (last command as root), then add 'extension=pdo_pgsql.so' to php.ini.
| |