mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Adding initial draft of PDO documentation
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@172413 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
d4e9167b33
commit
18cc72a0f0
10 changed files with 449 additions and 0 deletions
21
reference/pdo/functions/pdo-beginTransaction.xml
Normal file
21
reference/pdo/functions/pdo-beginTransaction.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.beginTransaction'>
|
||||
<refnamediv>
|
||||
<refname>beginTransaction</refname>
|
||||
<refpurpose>Begins a transaction.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>???</type> <methodname>beginTransaction</methodname>
|
||||
<void />
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Turns off autocommit mode. Call <function>commit</function> or
|
||||
<function>rollback</function> to end the transaction and return to
|
||||
autocommit mode.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
42
reference/pdo/functions/pdo-bindParam.xml
Normal file
42
reference/pdo/functions/pdo-bindParam.xml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.bindParam'>
|
||||
<refnamediv>
|
||||
<refname>bindParam</refname>
|
||||
<refpurpose>Binds a parameter to the specified variable name.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>???</type> <methodname>bindParam</methodname>
|
||||
<methodparam><type>String</type>
|
||||
<parameter>parameter-name</parameter></methodparam>
|
||||
<methodparam><type>var</type>
|
||||
<parameter>variable-name</parameter></methodparam>
|
||||
<methodparam choice='opt'><type>integer</type>
|
||||
<parameter>data-type</parameter></methodparam>
|
||||
<methodparam choice='opt'><type>integer</type>
|
||||
<parameter>length</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Binds a parameter to the specified variable name.
|
||||
</para>
|
||||
<example><title>Execute a prepared statement with bound variables</title>
|
||||
<programlisting role='php'><![CDATA[
|
||||
/* Execute a prepared statement by binding PHP variables */
|
||||
$calories = 150;
|
||||
$colour = 'red';
|
||||
$sth = $dbh->prepare('SELECT name, colour, calories
|
||||
FROM fruit
|
||||
WHERE calories < ?' AND colour = ?);
|
||||
$sth->bindParam(1, $calories, PDO_PARAM_INT)
|
||||
$sth->bindParam(2, $colour, PDO_PARAM_STR, 12)
|
||||
$sth->execute();
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
22
reference/pdo/functions/pdo-commit.xml
Normal file
22
reference/pdo/functions/pdo-commit.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.commit'>
|
||||
<refnamediv>
|
||||
<refname>commit</refname>
|
||||
<refpurpose>Commits a transaction.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>???</type> <methodname>commit</methodname>
|
||||
<void />
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Commits a transaction, returning the database connection to autocommit
|
||||
mode until the next call to <function>beginTransaction</function>
|
||||
starts a new transaction.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
53
reference/pdo/functions/pdo-execute.xml
Normal file
53
reference/pdo/functions/pdo-execute.xml
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.execute'>
|
||||
<refnamediv>
|
||||
<refname>execute</refname>
|
||||
<refpurpose>Executes a prepared statement.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>???</type> <methodname>execute</methodname>
|
||||
<methodparam choice='opt'><type>array</type>
|
||||
<parameter>parameters</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Execute the prepared statement. If the prepared statement included
|
||||
parameter markers, you must either:
|
||||
<itemizedlist>
|
||||
<listitem><para>call <function>bindParam</function> to bind PHP variables
|
||||
to the parameter markers: bound variables pass their value as input and receive the
|
||||
output value, if any, of their associated parameter markers</para></listitem>
|
||||
<listitem><para>or pass an array of parameter values</para></listitem>
|
||||
</itemizedlist>
|
||||
<example><title>Execute a prepared statement with bound variables</title>
|
||||
<programlisting role='php'><![CDATA[
|
||||
/* Execute a prepared statement by binding PHP variables */
|
||||
$calories = 150;
|
||||
$colour = 'red';
|
||||
$sth = $dbh->prepare('SELECT name, colour, calories
|
||||
FROM fruit
|
||||
WHERE calories < ?' AND colour = ?);
|
||||
$sth->bindParam(1, $calories, PDO_PARAM_INT)
|
||||
$sth->bindParam(2, $colour, PDO_PARAM_STR, 12)
|
||||
$sth->execute();
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example><title>Execute a prepared statement by passing an array of
|
||||
values</title>
|
||||
<programlisting role='php'><![CDATA[
|
||||
/* Execute a prepared statement by passing an array of values */
|
||||
$sth = $dbh->prepare('SELECT name, colour, calories
|
||||
FROM fruit
|
||||
WHERE calories < ?' AND colour = ?);
|
||||
$sth->execute(array(150, 'red'));
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
48
reference/pdo/functions/pdo-fetch.xml
Normal file
48
reference/pdo/functions/pdo-fetch.xml
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.fetch'>
|
||||
<refnamediv>
|
||||
<refname>fetch</refname>
|
||||
<refpurpose>Fetches a row from a result set.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>array</type> <methodname>fetch</methodname>
|
||||
<methodparam choice='opt'><type>integer</type>
|
||||
<parameter>PDO_FETCH_STYLE</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Fetches a row from a result set associated with a Statement object.
|
||||
</para>
|
||||
<para>
|
||||
<parameter>PDO_FETCH_STYLE</parameter> can be one of the following values:
|
||||
<itemizedlist>
|
||||
<listitem><para>PDO_FETCH_NUM: returns an array indexed by column number
|
||||
as returned in your result set, starting at column 0</para></listitem>
|
||||
<listitem><para>PDO_FETCH_ASSOC: returns an array indexed by column name
|
||||
as returned in your result set
|
||||
</para></listitem>
|
||||
<listitem><para>
|
||||
PDO_FETCH_BOTH (default): returns an array indexed by
|
||||
both column name and column number as returned in your result set
|
||||
</para></listitem>
|
||||
<listitem><para>
|
||||
PDO_FETCH_OBJ: returns an anonymous object with property names that
|
||||
correspond to the column names returned in your result set
|
||||
</para></listitem>
|
||||
<listitem><para>
|
||||
PDO_FETCH_LAZY: combines PDO_FETCH_BOTH and PDO_FETCH_OBJ, creating
|
||||
the object variable names as they are accessed
|
||||
</para></listitem>
|
||||
<listitem><para>
|
||||
PDO_FETCH_BOUND: returns TRUE and assigns the values of the columns in
|
||||
your result set to the PHP variables to which they were bound with the
|
||||
<function>bindParam</function> method
|
||||
</para></listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
33
reference/pdo/functions/pdo-prepare.xml
Normal file
33
reference/pdo/functions/pdo-prepare.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.prepare'>
|
||||
<refnamediv>
|
||||
<refname>prepare</refname>
|
||||
<refpurpose>Prepares an SQL statement.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>Statement</type> <methodname>prepare</methodname>
|
||||
<methodparam><type>String</type> <parameter>SQL-statement</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Prepares an SQL statement to be executed by the statement-handle
|
||||
<function>execute</function> method. The SQL statement can contain zero
|
||||
or more parameter markers.
|
||||
</para>
|
||||
<example><title>Execute a prepared statement by passing an array of
|
||||
values</title>
|
||||
<programlisting role='php'><![CDATA[
|
||||
/* Execute a prepared statement by passing an array of values */
|
||||
$sth = $dbh->prepare('SELECT name, colour, calories
|
||||
FROM fruit
|
||||
WHERE calories < ?' AND colour = ?);
|
||||
$sth->execute(array(150, 'red'));
|
||||
]]></programlisting>
|
||||
</example>
|
||||
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
20
reference/pdo/functions/pdo-rollback.xml
Normal file
20
reference/pdo/functions/pdo-rollback.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.rollback'>
|
||||
<refnamediv>
|
||||
<refname>rollback</refname>
|
||||
<refpurpose>Rolls back a transaction.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>???</type> <methodname>rollback</methodname>
|
||||
<void />
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Rolls back a transaction, returning the connection state to autocommit mode.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
35
reference/pdo/functions/pdo-setAttribute.xml
Normal file
35
reference/pdo/functions/pdo-setAttribute.xml
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo.setAttribute'>
|
||||
<refnamediv>
|
||||
<refname>setAttribute</refname>
|
||||
<refpurpose>Sets a database connection attribute.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>???</type> <methodname>setAttribute</methodname>
|
||||
<methodparam><type>int</type> <parameter>attribute</parameter></methodparam>
|
||||
<methodparam><type>int</type> <parameter>value</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
Sets a database connection attribute. The generic PDO connection attributes
|
||||
include:
|
||||
<itemizedlist>
|
||||
<listitem><para>PDO_ATTR_CASE: Force column names to a specific case.
|
||||
<itemizedlist>
|
||||
<listitem><para>PDO_CASE_LOWER: Force column names to lower
|
||||
case.</para></listitem>
|
||||
<listitem><para>PDO_CASE_NATURAL: Leave column names as returned by
|
||||
the database driver.</para></listitem>
|
||||
<listitem><para>PDO_CASE_UPPER: Force column names to upper
|
||||
case.</para></listitem>
|
||||
</itemizedlist>
|
||||
</para></listitem>
|
||||
</itemizedlist>
|
||||
PDO drivers may define further driver-specific attributes.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
57
reference/pdo/functions/pdo.xml
Normal file
57
reference/pdo/functions/pdo.xml
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<refentry id='function.pdo'>
|
||||
<refnamediv>
|
||||
<refname>PDO</refname>
|
||||
<refpurpose>Creates a PDO instance to represent a connection to a
|
||||
database.</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>object</type> <methodname>PDO</methodname>
|
||||
<methodparam><type>String</type> <parameter>DSN</parameter></methodparam>
|
||||
<methodparam choice='opt'><type>String</type> <parameter>username</parameter></methodparam>
|
||||
<methodparam choice='opt'><type>String</type> <parameter>password</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
&warn.experimental.func;
|
||||
<para>
|
||||
The format of the Data Source Name (DSN) parameter is:
|
||||
<itemizedlist>
|
||||
<listitem><para>PDO driver, followed by a colon</para></listitem>
|
||||
<listitem><para>followed by optional driver-specific
|
||||
information</para></listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
To close a database connection:
|
||||
<itemizedlist>
|
||||
<listitem><para>assign a &null; value to the PDO object</para></listitem>
|
||||
<listitem><para>let the PDO object go out of scope</para></listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<para>
|
||||
Connections are automatically in autocommit mode. Invoke the
|
||||
<function>beginTransaction</function> method to turn off autocommit, and
|
||||
call <function>commit</function> or <function>rollback</function> to end
|
||||
the transaction. PDO automatically rolls back transactions that are ended
|
||||
by a closed connection handle.
|
||||
</para>
|
||||
<example><title>Create a connection</title>
|
||||
<programlisting role='php'><![CDATA[
|
||||
$database = 'SAMPLE';
|
||||
$user = 'db2inst1';
|
||||
$password = 'ibmdb2';
|
||||
try {
|
||||
$dbh = new PDO("ODBC:$database", $user, $password);
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
echo "Could not connect to database '$database' as user '$user'.";
|
||||
echo $e->getMessage();
|
||||
}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
118
reference/pdo/reference.xml
Normal file
118
reference/pdo/reference.xml
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision -->
|
||||
<reference id='ref.pdo'>
|
||||
<title>PHP Data Objects</title>
|
||||
<titleabbrev>PDO</titleabbrev>
|
||||
<partintro>
|
||||
<section id='pdo.initro'>
|
||||
&reftitle.intro;
|
||||
<para>
|
||||
&warn.experimental;
|
||||
The 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.
|
||||
</para>
|
||||
</section>
|
||||
<!--
|
||||
&reference.pdo.configure;
|
||||
&reference.pdo.ini;
|
||||
-->
|
||||
<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'>PDO</link> - construct 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> - begin a transaction</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><link linkend='function.pdo-commit'>commit</link> - commit a
|
||||
transaction</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-getMessage'>getMessage</link> -
|
||||
retrieves an error message, if any, from the database</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-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.classes.Statement'>
|
||||
<title><classname>Statement</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.pdo-bindParam'>bindParam</link> - binds a
|
||||
PHP variable to a parameter in the prepared statement</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><link linkend='function.pdo-execute'>execute</link> - executes a
|
||||
prepared statement</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para><link linkend='function.pdo-fetch'>fetch</link> - fetches a
|
||||
row from a result set</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</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
|
||||
-->
|
Loading…
Reference in a new issue