php-doc-en/reference/pdo/reference.xml

447 lines
14 KiB
XML
Raw Normal View History

<?xml version='1.0' encoding='iso-8859-1'?>
<!-- $Revision: 1.33 $ -->
<!-- Purpose: database.abstract -->
<!-- Membership: pecl, bundled -->
<!-- State:experimental -->
<reference id="ref.pdo">
<title>PDO Functions</title>
<titleabbrev>PDO</titleabbrev>
<partintro>
<section id="pdo.intro">
&reftitle.intro;
<para>
&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 <link linkend="pdo.drivers">database-specific
PDO driver</link> to access a database server.
</para>
<para>
PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0;
PDO requires the new OO features in the core of PHP 5, and so will not
run with earlier versions of PHP.
</para>
</section>
<section id="pdo.installation">
&reftitle.install;
<procedure id='pdo.install.unix51up'>
<title>PHP 5.1 and up on Unix systems</title>
<step>
<para>
If you're running a PHP 5.1 release, PDO is included in the distribution;
it will be automatically enabled when you run configure. It is
recommended that you build PDO as a shared extension, as this will allow
you to take advantage of updates that are made available via PECL. The
recommended configure line for building PHP with PDO support should
enable zlib support (for the pear installer) as well. You may also need
to enable the PDO driver for your database of choice; consult the
documentation for <link linkend="pdo.drivers">database-specific
PDO drivers</link> to find out more about that.
<screen>
<![CDATA[
./configure --with-zlib --enable-pdo=shared
]]>
</screen>
</para>
</step>
<step>
<para>
After installing PDO as a shared module, you must edit your php.ini file
so that the PDO extension will be loaded automatically when PHP runs.
You will also need to enable any database specific drivers there too;
make sure that they are listed after the pdo.so line, as PDO must be
initialized before the database specific extensions can be loaded.
If you built the extensions statically, you can skip this step.
<screen>
<![CDATA[
extension=pdo.so
]]>
</screen>
</para>
</step>
<step>
<para>
Having PDO as a shared module will allow you to run <command>pear
upgrade pdo</command> as new versions of PDO are published, without
forcing you to rebuild the whole of PHP. Note that if you do this, you
also need to upgrade your database specific PDO drivers at the same
time.
</para>
</step>
</procedure>
<procedure id='pdo.install.pecl'>
<title>PHP 5.0 and up on Unix systems</title>
<step>
<para>
PDO is available as a PECL extension from
<ulink url='&url.pecl.package;pdo'>&url.pecl.package;pdo</ulink>.
Installation can be performed via the <command>pear</command> tool; this
is enabled by default when you configure PHP. You should ensure that
PHP was configured --with-zlib in order for
<command>pear</command> to be able to handle the compressed package
files.
</para>
</step>
<step>
<para>
Run the following command to download, build, and install the
latest stable version of PDO:
<screen>
<![CDATA[
pear install pdo
]]>
</screen>
</para>
</step>
<step>
<para>
If PDO is still in beta (and at the time of writing, it is), you will
need to tell the pear tool that it's ok to fetch the beta package.
Instead of running the command above, run the following:
<screen>
<![CDATA[
pear install pdo-beta
]]>
</screen>
</para>
</step>
<step>
<para>
The <command>pear</command> 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;:
<screen>
<![CDATA[
extension=pdo.so
]]>
</screen>
</para>
</step>
</procedure>
<procedure id='pdo.install.win32php51'>
<title>Windows users running PHP 5.1 and up</title>
<step>
<para>
PDO and all the major drivers ship with PHP as shared extensions, and
simply need to be activated by editing the &php.ini; file:
<screen>
<![CDATA[
extension=php_pdo.dll
]]>
</screen>
</para>
</step>
<step>
<para>
Next, choose the other DB specific DLL files and either use
<function>dl</function> to load them at runtime, or enable them in
&php.ini; below <filename>php_pdo.dll</filename>. For example:
<screen>
<![CDATA[
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
]]>
</screen>
</para>
<para>
These DLLs should exist in the system's
<link linkend="ini.extension-dir">extension_dir</link>.
</para>
</step>
</procedure>
</section>
&reference.pdo.ini;
<section id="pdo.drivers">
<title>PDO Drivers</title>
<para>
The following drivers currently implement the PDO interface:
<informaltable>
<tgroup cols='2'>
<thead>
<row>
<entry>Driver name</entry>
<entry>Supported databases</entry>
</row>
</thead>
<tbody>
<row>
<entry><link linkend="ref.pdo-dblib">PDO_DBLIB</link></entry>
<entry>FreeTDS / Microsoft SQL Server / Sybase</entry>
</row>
<row>
<entry><link linkend="ref.pdo-firebird">PDO_FIREBIRD</link></entry>
<entry>Firebird/Interbase 6</entry>
</row>
<row>
<entry><link linkend="ref.pdo-mysql">PDO_MYSQL</link></entry>
<entry>MySQL 3.x/4.x</entry>
</row>
<row>
<entry><link linkend="ref.pdo-oci">PDO_OCI</link></entry>
<entry>Oracle Call Interface</entry>
</row>
<row>
<entry><link linkend="ref.pdo-odbc">PDO_ODBC</link></entry>
<entry>ODBC v3 (IBM DB2, unixODBC and win32 ODBC)</entry>
</row>
<row>
<entry><link linkend="ref.pdo-pgsql">PDO_PGSQL</link></entry>
<entry>PostgreSQL</entry>
</row>
<row>
<entry><link linkend="ref.pdo-sqlite">PDO_SQLITE</link></entry>
<entry>SQLite 3 and SQLite 2</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</section>
<section id='pdo.classes'>
&reftitle.classes;
<section id='pdo.class.PDO'>
<title><classname>PDO</classname></title>
<para>
Represents a connection between PHP and a database server.
</para>
<section id='pdo.class.PDO.constructor'>
&reftitle.constructor;
<itemizedlist>
<listitem>
<para>
<link linkend='function.PDO-construct'>PDO</link> - constructs a new
PDO object
</para>
</listitem>
</itemizedlist>
</section>
<section id='pdo.class.PDO.methods'>
&reftitle.methods;
<itemizedlist>
<listitem>
<para>
<link linkend='function.PDO-beginTransaction'>beginTransaction</link>
- begins a transaction
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-commit'>commit</link>
- commits a transaction
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-exec'>exec</link>
- issues an SQL statement and returns the number of affected rows
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-errorCode'>errorCode</link>
- retrieves an error code, if any, from the database
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-errorInfo'>errorInfo</link>
- retrieves an array of error information, if any, from the
database
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-getAttribute'>getAttribute</link>
- retrieves a database connection attribute
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-lastInsertId'>lastInsertId</link>
- retrieves the value of the last row that was inserted into a table
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-prepare'>prepare</link>
- prepares an SQL statement for execution
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-query'>query</link>
- issues an SQL statement and returns a result set
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-quote'>quote</link>
- returns a quoted version of a string for use in SQL statements
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-rollBack'>rollBack</link>
- roll back a transaction
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDO-setAttribute'>setAttribute</link>
- sets a database connection attribute
</para>
</listitem>
</itemizedlist>
</section>
</section>
<section id='pdo.class.PDOStatement'>
<title><classname>PDOStatement</classname></title>
<para>
Represents a prepared statement and, after the statement is executed, an
associated result set.
</para>
<section id='pdo.class.Statement.methods'>
&reftitle.methods;
<itemizedlist>
<listitem>
<para>
<link linkend='function.PDOStatement-bindColumn'>bindColumn</link>
- binds a PHP variable to an output column in a result set
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-bindParam'>bindParam</link>
- binds a PHP variable to a parameter in the prepared statement
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-closeCursor'>closeCursor</link>
- closes the cursor, allowing the statement to be executed again
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-columnCount'>columnCount</link>
- returns the number of columns in the result set
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-errorCode'>errorCode</link>
- retrieves an error code, if any, from the statement
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-errorInfo'>errorInfo</link>
- retrieves an array of error information, if any, from the statement
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-execute'>execute</link>
- executes a prepared statement
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-fetch'>fetch</link>
- fetches a row from a result set
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-fetchAll'>fetchAll</link>
- fetches an array containing all of the rows from a result set
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-fetchColumn'>fetchColumn</link>
- returns the data from a single column in a result set
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-getAttribute'>getAttribute</link>
- retrieves a PDOStatement attribute
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-getColumnMeta'>getColumnMeta</link>
- retrieves metadata for a column in the result set
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-nextRowset'>nextRowset</link>
- retrieves the next rowset (result set)
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-rowCount'>rowCount</link>
- returns the number of rows that were affected by the execution of
an SQL statement
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-setAttribute'>setAttribute</link>
- sets a PDOStatement attribute
</para>
</listitem>
<listitem>
<para>
<link linkend='function.PDOStatement-setFetchMode'>setFetchMode</link>
- sets the fetch mode for a PDOStatement
</para>
</listitem>
</itemizedlist>
</section>
</section>
</section>
&reference.pdo.constants;
</partintro>
&reference.pdo.functions;
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->