cvs: phpdoc /en/reference/pdo/functions PDO-beginTransaction.xml PDO-commit.xml PDO-construct.xml PDO-errorCode.xml PDO-errorInfo.xml PDO-exec.xml
PDO-getAttribute.xml PDO-getAvailableDrivers.xml PDO-lastInsertId.xml PDO-prepare.xml PDO-query.xml PDO-quote.xml PDO-rollBack.xml
PDO-setAttribute.xml PDOStatement-bindColumn.xml PDOStatement-bindParam.xml PDOStatement-bindValue.xml PDOStatement-closeCursor.xml
PDOStatement-columnCount.xml PDOStatement-errorCode.xml PDOStatement-errorInfo.xml PDOStatement-execute.xml PDOStatement-fetch.xml
PDOStatement-fetchAll.xml PDOStatement-fetchColumn.xml PDOStatement-fetchObject.xml PDOStatement-getAttribute.xml PDOStatement-getColumnMeta.xml
PDOStatement-nextRowset.xml PDOStatement-rowCount.xml PDOStatement-setAttribute.xml PDOStatement-setFetchMode.xml /en/reference/pdo/pdo
begintransaction.xml commit.xml construct.xml errorcode.xml errorinfo.xml exec.xml getattribute.xml getavailabledrivers.xml lastinsertid.xml
prepare.xml quer! y.xml quote.xml rollback.xml setattribute.xml /en/reference/pdo/pdostatement bindcolumn.xml bindparam.xml bindvalue.xml
closecursor.xml columncount.xml errorcode.xml errorinfo.xml execute.xml fetch.xml fetchall.xml fetchcolumn.xml fetchobject.xml getattribute.xml
getcolumnmeta.xml nextrowset.xml rowcount.xml setattribute.xml setfetchmode.xml
| From: | Hannes Magnusson | Date: | Mon, 31 Dec 2007 14:29:37 +0000 |
| Subject: | cvs: phpdoc /en/reference/pdo/functions PDO-beginTransaction.xml PDO-commit.xml PDO-construct.xml PDO-errorCode.xml PDO-errorInfo.xml PDO-exec.xml PDO-getAttribute.xml PDO-getAvailableDrivers.xml PDO-lastInsertId.xml PDO-prepare.xml PDO-query.xml PDO-quote.xml PDO-rollBack.xml PDO-setAttribute.xml PDOStatement-bindColumn.xml PDOStatement-bindParam.xml PDOStatement-bindValue.xml PDOStatement-closeCursor.xml PDOStatement-columnCount.xml PDOStatement-errorCode.xml PDOStatement-errorInfo.xml PDOStatement-execute.xml PDOStatement-fetch.xml PDOStatement-fetchAll.xml PDOStatement-fetchColumn.xml PDOStatement-fetchObject.xml PDOStatement-getAttribute.xml PDOStatement-getColumnMeta.xml PDOStatement-nextRowset.xml PDOStatement-rowCount.xml PDOStatement-setAttribute.xml PDOStatement-setFetchMode.xml /en/reference/pdo/pdo begintransaction.xml commit.xml construct.xml errorcode.xml errorinfo.xml exec.xml getattribute.xml getavailabledrivers.xml lastinsertid.xml prepare.xml quer! y.xml quote.xml rollback.xml setattribute.xml /en/reference/pdo/pdostatement bindcolumn.xml bindparam.xml bindvalue.xml closecursor.xml columncount.xml errorcode.xml errorinfo.xml execute.xml fetch.xml fetchall.xml fetchcolumn.xml fetchobject.xml getattribute.xml getcolumnmeta.xml nextrowset.xml rowcount.xml setattribute.xml setfetchmode.xml |
||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-962@lists.php.net to get a copy of this message | ||
bjori Mon Dec 31 14:29:37 2007 UTC
Added files:
/phpdoc/en/reference/pdo/pdo begintransaction.xml commit.xml
construct.xml errorcode.xml
errorinfo.xml exec.xml
getattribute.xml
getavailabledrivers.xml
lastinsertid.xml prepare.xml query.xml
quote.xml rollback.xml
setattribute.xml
/phpdoc/en/reference/pdo/pdostatement bindcolumn.xml bindparam.xml
bindvalue.xml closecursor.xml
columncount.xml errorcode.xml
errorinfo.xml execute.xml
fetch.xml fetchall.xml
fetchcolumn.xml
fetchobject.xml
getattribute.xml
getcolumnmeta.xml
nextrowset.xml rowcount.xml
setattribute.xml
setfetchmode.xml
Removed files:
/phpdoc/en/reference/pdo/functions PDO-beginTransaction.xml
PDO-commit.xml PDO-construct.xml
PDO-errorCode.xml
PDO-errorInfo.xml PDO-exec.xml
PDO-getAttribute.xml
PDO-getAvailableDrivers.xml
PDO-lastInsertId.xml
PDO-prepare.xml PDO-query.xml
PDO-quote.xml PDO-rollBack.xml
PDO-setAttribute.xml
PDOStatement-bindColumn.xml
PDOStatement-bindParam.xml
PDOStatement-bindValue.xml
PDOStatement-closeCursor.xml
PDOStatement-columnCount.xml
PDOStatement-errorCode.xml
PDOStatement-errorInfo.xml
PDOStatement-execute.xml
PDOStatement-fetch.xml
PDOStatement-fetchAll.xml
PDOStatement-fetchColumn.xml
PDOStatement-fetchObject.xml
PDOStatement-getAttribute.xml
PDOStatement-getColumnMeta.xml
PDOStatement-nextRowset.xml
PDOStatement-rowCount.xml
PDOStatement-setAttribute.xml
PDOStatement-setFetchMode.xml
Log:
Lowercase, rename, and move as per the new-oo-style
- functions/PDOStatement-*.xml to pdostatement/*.xml
- functions/PDO-*.xml to pdo/*.xml
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/begintransaction.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/begintransaction.xml +++ phpdoc/en/reference/pdo/pdo/begintransaction.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-beginTransaction" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->beginTransaction()</refname> <refpurpose> Initiates a transaction </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>beginTransaction</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO object instance are not committed until you end the transaction by calling <xref linkend="function.PDO-commit" />. Calling <xref linkend="function.PDO-rollBack" /> will roll back all changes to the database and return the connection to autocommit mode. </para> <para> Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Roll back a transaction</title> <para> The following example begins a transaction and issues two statements that modify the database before rolling back the changes. On MySQL, however, the DROP TABLE statement automatically commits the transaction so that none of the changes in the transaction are rolled back. </para> <programlisting role='php'> <![CDATA[ <?php /* Begin a transaction, turning off autocommit */ $dbh->beginTransaction(); /* Change the database schema and data */ $sth = $dbh->exec("DROP TABLE fruit"); $sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'"); /* Recognize mistake and roll back changes */ $dbh->rollBack(); /* Database connection is now back in autocommit mode */ ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-commit" /></member> <member><xref linkend="function.PDO-rollBack" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/commit.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/commit.xml +++ phpdoc/en/reference/pdo/pdo/commit.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-commit" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->commit()</refname> <refpurpose> Commits a transaction </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>commit</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Commits a transaction, returning the database connection to autocommit mode until the next call to <xref linkend="function.PDO-beginTransaction" /> starts a new transaction. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Commit a transaction</title> <programlisting role='php'> <![CDATA[ <?php /* Begin a transaction, turning off autocommit */ $dbh->beginTransaction(); /* Change the database schema */ $sth = $dbh->exec("DROP TABLE fruit"); /* Commit the changes */ $dbh->commit(); /* Database connection is now back in autocommit mode */ ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-beginTransaction" /></member> <member><xref linkend="function.PDO-rollBack" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/construct.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/construct.xml +++ phpdoc/en/reference/pdo/pdo/construct.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-construct" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->__construct()</refname> <refpurpose> Creates a PDO instance representing a connection to a database </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDO</type><methodname>__construct</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> <methodparam choice="opt"><type>array</type><parameter>driver_options</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Creates a PDO instance to represent a connection to the requested database. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry><term>dsn</term> <listitem> <para> The Data Source Name, or DSN, contains the information required to connect to the database. </para> <para> In general, a DSN consists of the PDO driver name, followed by a colon, followed by the PDO driver-specific connection syntax. Further information is available from the <link linkend="pdo.drivers">PDO driver-specific documentation</link>. </para> <para> The <parameter>dsn</parameter> parameter supports three different methods of specifying the arguments required to create a database connection: </para> <para> <variablelist> <varlistentry><term>Driver invocation</term> <listitem> <para> <parameter>dsn</parameter> contains the full DSN. </para> </listitem> </varlistentry> <varlistentry><term>URI invocation</term> <listitem> <para> <parameter>dsn</parameter> consists of <userinput>uri:</userinput> followed by a URI that defines the location of a file containing the DSN string. The URI can specify a local file or a remote URL. </para> <para><userinput>uri:file:///path/to/dsnfile</userinput></para> </listitem> </varlistentry> <varlistentry><term>Aliasing</term> <listitem> <para> <parameter>dsn</parameter> consists of a name <parameter>name</parameter> that maps to <code>pdo.dsn.<parameter>name</parameter></code> in &php.ini; defining the DSN string. </para> <note> <para> The alias must be defined in &php.ini;, and not &htaccess; or &httpd.conf; </para> </note> </listitem> </varlistentry> </variablelist> </para> </listitem> </varlistentry> <varlistentry><term>username</term> <listitem> <para> The user name for the DSN string. This parameter is optional for some PDO drivers. </para> </listitem> </varlistentry> <varlistentry><term>password</term> <listitem> <para> The password for the DSN string. This parameter is optional for some PDO drivers. </para> </listitem> </varlistentry> <varlistentry><term>driver_options</term> <listitem> <para> A key=>value array of driver-specific connection options. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns a PDO object on success. </para> </refsect1> <refsect1 role="errors"> &reftitle.errors; <para> <xref linkend="function.PDO-construct" /> throws a PDOException if the attempt to connect to the requested database fails. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Create a PDO instance via driver invocation</title> <programlisting role="php"> <![CDATA[ <?php /* Connect to an ODBC database using driver invocation */ $dsn = 'mysql:dbname=testdb;host=127.0.0.1'; $user = 'dbuser'; $password = 'dbpass'; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } ?> ]]> </programlisting> </example> <example><title>Create a PDO instance via URI invocation</title> <para> The following example assumes that the file <filename>/usr/local/dbconnect</filename> exists with file permissions that enable PHP to read the file. The file contains the PDO DSN to connect to a DB2 database through the PDO_ODBC driver: </para> <screen> <![CDATA[ odbc:DSN=SAMPLE;UID=john;PWD=mypass ]]> </screen> <para> The PHP script can then create a database connection by simply passing the <literal>uri:</literal> parameter and pointing to the file URI: </para> <programlisting role="php"> <![CDATA[ <?php /* Connect to an ODBC database using driver invocation */ $dsn = 'uri:file:///usr/local/dbconnect'; $user = ''; $password = ''; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } ?> ]]> </programlisting> </example> <example><title>Create a PDO instance using an alias</title> <para> The following example assumes that &php.ini; contains the following entry to enable a connection to a MySQL database using only the alias <literal>mydb</literal>: <programlisting role="ini"> [PDO] pdo.dsn.mydb="mysql:dbname=testdb;host=localhost" </programlisting> </para> <programlisting role="php"> <![CDATA[ <?php /* Connect to an ODBC database using an alias */ $dsn = 'mydb'; $user = ''; $password = ''; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } ?> ]]> </programlisting> </example> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/errorcode.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/errorcode.xml +++ phpdoc/en/reference/pdo/pdo/errorcode.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-errorCode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->errorCode()</refname> <refpurpose> Fetch the SQLSTATE associated with the last operation on the database handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>string</type><methodname>errorCode</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns a SQLSTATE, a five-character alphanumeric identifier defined in the ANSI SQL-92 standard. Briefly, an SQLSTATE consists of a two-character class value followed by a three-character subclass value. A class value of 01 indicates a warning and is accompanied by a return code of SQL_SUCCESS_WITH_INFO. Class values other than '01', except for the class 'IM', indicate an error. The class 'IM' is specific to warnings and errors that derive from the implementation of PDO (or perhaps ODBC, if you're using the ODBC driver) itself. The subclass value '000' in any class indicates that there is no subclass for that SQLSTATE. </para> <para> <xref linkend="function.PDO-errorCode" /> only retrieves error codes for operations performed directly on the database handle. If you create a PDOStatement object through <xref linkend="function.PDO-prepare" /> or <xref linkend="function.PDO-query" /> and invoke an error on the statement handle, <xref linkend="function.PDO-errorCode" /> will not reflect that error. You must call <xref linkend="function.PDOStatement-errorCode" /> to return the error code for an operation performed on a particular statement handle. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Retrieving a SQLSTATE code</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- the BONES table does not exist */ $dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')"); echo "\nPDO::errorCode(): "; print $dbh->errorCode(); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDO::errorCode(): 42S02 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorInfo" /></member> <member><xref linkend="function.PDOStatement-errorCode" /></member> <member><xref linkend="function.PDOStatement-errorInfo" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/errorinfo.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/errorinfo.xml +++ phpdoc/en/reference/pdo/pdo/errorinfo.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-errorInfo" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->errorInfo()</refname> <refpurpose> Fetch extended error information associated with the last operation on the database handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>array</type><methodname>errorInfo</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-errorInfo" /> returns an array of error information about the last operation performed by this database handle. The array consists of the following fields: <informaltable> <tgroup cols='2'> <thead> <row> <entry>Element</entry> <entry>Information</entry> </row> </thead> <tbody> <row> <entry>0</entry> <entry>SQLSTATE error code (a five-character alphanumeric identifier defined in the ANSI SQL standard).</entry> </row> <row> <entry>1</entry> <entry>Driver-specific error code.</entry> </row> <row> <entry>2</entry> <entry>Driver-specific error message.</entry> </row> </tbody> </tgroup> </informaltable> </para> <para> <xref linkend="function.PDO-errorInfo" /> only retrieves error information for operations performed directly on the database handle. If you create a PDOStatement object through <xref linkend="function.PDO-prepare" /> or <xref linkend="function.PDO-query" /> and invoke an error on the statement handle, <xref linkend="function.PDO-errorInfo" /> will not reflect the error from the statement handle. You must call <xref linkend="function.PDOStatement-errorInfo" /> to return the error information for an operation performed on a particular statement handle. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Displaying errorInfo() fields for a PDO_ODBC connection to a DB2 database</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- bogus SQL syntax */ $stmt = $dbh->prepare('bogus sql'); if (!$stmt) { echo "\nPDO::errorInfo():\n"; print_r($dbh->errorInfo()); } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDO::errorInfo(): Array ( [0] => HY000 [1] => 1 [2] => near "bogus": syntax error ) ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorCode" /></member> <member><xref linkend="function.PDOStatement-errorCode" /></member> <member><xref linkend="function.PDOStatement-errorInfo" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/exec.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/exec.xml +++ phpdoc/en/reference/pdo/pdo/exec.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-exec" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->exec()</refname> <refpurpose> Execute an SQL statement and return the number of affected rows </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>int</type><methodname>exec</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDO-exec" /> executes an SQL statement in a single function call, returning the number of rows affected by the statement. </para> <para> <xref linkend="function.PDO-exec" /> does not return results from a SELECT statement. For a SELECT statement that you only need to issue once during your program, consider issuing <xref linkend="function.PDO-query" />. For a statement that you need to issue multiple times, prepare a PDOStatement object with <xref linkend="function.PDO-prepare" /> and issue the statement with <xref linkend="function.PDOStatement-execute" />. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>statement</parameter></term> <listitem> <para> The SQL statement to prepare and execute. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-exec" /> returns the number of rows that were modified or deleted by the SQL statement you issued. If no rows were affected, <xref linkend="function.PDO-exec" /> returns <literal>0</literal>. </para> &return.falseproblem; <para> The following example incorrectly relies on the return value of <xref linkend="function.PDO-exec" />, wherein a statement that affected 0 rows results in a call to <function>die</function>: <programlisting role="php"> <![CDATA[ <?php $db->exec() or die($db->errorInfo()); ?> ]]> </programlisting> </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Issuing a DELETE statement</title> <para> Count the number of rows deleted by a DELETE statement with no WHERE clause. </para> <programlisting role="php"> <![CDATA[ <?php $dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); /* Delete all rows from the FRUIT table */ $count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'"); /* Return number of rows that were deleted */ print("Deleted $count rows.\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Deleted 1 rows. ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/getattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/getattribute.xml +++ phpdoc/en/reference/pdo/pdo/getattribute.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-getAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->getAttribute()</refname> <refpurpose> Retrieve a database connection attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>getAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> This function returns the value of a database connection attribute. To retrieve PDOStatement attributes, refer to <xref linkend="function.PDOStatement-getAttribute" />. </para> <para> Note that some database/driver combinations may not support all of the database connection attributes. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>attribute</parameter></term> <listitem> <para> One of the <literal>PDO::ATTR_*</literal> constants. The constants that apply to database connections are as follows: <simplelist> <member><literal>PDO::ATTR_AUTOCOMMIT</literal></member> <member><literal>PDO::ATTR_CASE</literal></member> <member><literal>PDO::ATTR_CLIENT_VERSION</literal></member> <member><literal>PDO::ATTR_CONNECTION_STATUS</literal></member> <member><literal>PDO::ATTR_DRIVER_NAME</literal></member> <member><literal>PDO::ATTR_ERRMODE</literal></member> <member><literal>PDO::ATTR_ORACLE_NULLS</literal></member> <member><literal>PDO::ATTR_PERSISTENT</literal></member> <member><literal>PDO::ATTR_PREFETCH</literal></member> <member><literal>PDO::ATTR_SERVER_INFO</literal></member> <member><literal>PDO::ATTR_SERVER_VERSION</literal></member> <member><literal>PDO::ATTR_TIMEOUT</literal></member> </simplelist> </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> A successful call returns the value of the requested PDO attribute. An unsuccessful call returns <literal>null</literal>. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Retrieving database connection attributes</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); $attributes = array( "AUTOCOMMIT", "ERRMODE", "CASE", "CLIENT_VERSION", "CONNECTION_STATUS", "ORACLE_NULLS", "PERSISTENT", "PREFETCH", "SERVER_INFO", "SERVER_VERSION", "TIMEOUT" ); foreach ($attributes as $val) { echo "PDO::ATTR_$val: "; echo $conn->getAttribute(constant("PDO::ATTR_$val")) . "\n"; } ?> ]]> </programlisting> <!-- &example.outputs; <screen> <![CDATA[ Use the PEAR Coding Standards ]]> </screen> --> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-setAttribute" /></member> <member><xref linkend="function.PDOStatement-getAttribute" /></member> <member><xref linkend="function.PDOStatement-setAttribute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/getavailabledrivers.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/getavailabledrivers.xml +++ phpdoc/en/reference/pdo/pdo/getavailabledrivers.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-getAvailableDrivers" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->getAvailableDrivers()</refname> <refpurpose> Return an array of available PDO drivers </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>array</type><methodname>getAvailableDrivers</methodname> <void/> </methodsynopsis> </classsynopsis> <para> This function returns all currently available PDO drivers which can be used in <parameter>DSN</parameter> parameter of <xref linkend="function.PDO-construct" />. This is a static method. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-getAvailableDrivers" /> returns an array of PDO driver names. If no drivers are available, it returns an empty array. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>A <xref linkend="function.PDO-getAvailableDrivers" /> example</title> <programlisting role="php"> <![CDATA[ <?php print_r(PDO::getAvailableDrivers()); ?> ]]> </programlisting> &example.outputs.similar; <screen> <![CDATA[ Array ( [0] => mysql [1] => sqlite ) ]]> </screen> </example> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/lastinsertid.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/lastinsertid.xml +++ phpdoc/en/reference/pdo/pdo/lastinsertid.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-lastInsertId" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->lastInsertId()</refname> <refpurpose> Returns the ID of the last inserted row or sequence value </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>string</type><methodname>lastInsertId</methodname> <methodparam choice="opt"><type>string</type><parameter>name</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver. For example, <function>PDO_PGSQL</function> requires you to specify the name of a sequence object for the <parameter>name</parameter> parameter. </para> <note> <para> This method may not return a meaningful or consistent result across different PDO drivers, because the underlying database may not even support the notion of auto-increment fields or sequences. </para> </note> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>name</parameter></term> <listitem> <para> Name of the sequence object from which the ID should be returned. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> If a sequence name was not specified for the <parameter>name</parameter> parameter, <xref linkend="function.PDO-lastInsertId" /> returns a string representing the row ID of the last row that was inserted into the database. </para> <para> If a sequence name was specified for the <parameter>name</parameter> parameter, <xref linkend="function.PDO-lastInsertId" /> returns a string representing the last value retrieved from the specified sequence object. </para> <para> If the PDO driver does not support this capability, <xref linkend="function.PDO-lastInsertId" /> triggers an <literal>IM001</literal> SQLSTATE. </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/prepare.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/prepare.xml +++ phpdoc/en/reference/pdo/pdo/prepare.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-prepare" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->prepare()</refname> <refpurpose> Prepares a statement for execution and returns a statement object </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>prepare</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>driver_options</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Prepares an SQL statement to be executed by the <xref linkend="function.PDOStatement-execute" /> method. The SQL statement can contain zero or more named (:name) or question mark (?) parameter markers for which real values will be substituted when the statement is executed. You cannot use both named and question mark parameter markers within the same SQL statement; pick one or the other parameter style. </para> <para> You must include a unique parameter marker for each value you wish to pass in to the statement when you call <xref linkend="function.PDOStatement-execute" />. You cannot use a named parameter marker of the same name twice in a prepared statement. You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement. </para> <para> Calling <xref linkend="function.PDO-prepare" /> and <xref linkend="function.PDOStatement-execute" /> for statements that will be issued multiple times with different parameter values optimizes the performance of your application by allowing the driver to negotiate client and/or server side caching of the query plan and meta information, and helps to prevent SQL injection attacks by eliminating the need to manually quote the parameters. </para> <para> PDO will emulate prepared statements/bound parameters for drivers that do not natively support them, and can also rewrite named or question mark style parameter markers to something more appropriate, if the driver supports one style but not the other. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>statement</parameter></term> <listitem> <para> This must be a valid SQL statement for the target database server. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>driver_options</parameter></term> <listitem> <para> This array holds one or more key=>value pairs to set attribute values for the PDOStatement object that this method returns. You would most commonly use this to set the <literal>PDO::ATTR_CURSOR</literal> value to <literal>PDO::CURSOR_SCROLL</literal> to request a scrollable cursor. Some drivers have driver specific options that may be set at prepare-time. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> If the database server successfully prepares the statement, <xref linkend="function.PDO-prepare" /> returns a PDOStatement object. If the database server cannot successfully prepare the statement, <xref linkend="function.PDO-prepare" /> returns &false;. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Prepare an SQL statement with named parameters</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by passing an array of values */ $sql = 'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'; $sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $sth->execute(array(':calories' => 150, ':colour' => 'red')); $red = $sth->fetchAll(); $sth->execute(array('calories' => 175, 'colour' => 'yellow')); $yellow = $sth->fetchAll(); ?> ]]> </programlisting> </example> <example> <title>Prepare an SQL statement with question mark parameters</title> <programlisting role='php'> <![CDATA[ <?php /* 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')); $red = $sth->fetchAll(); $sth->execute(array(175, 'yellow')); $yellow = $sth->fetchAll(); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-exec" /></member> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/query.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/query.xml +++ phpdoc/en/reference/pdo/pdo/query.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-query" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->query()</refname> <refpurpose> Executes an SQL statement, returning a result set as a PDOStatement object </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam><type>int</type><parameter>PDO::FETCH_COLUMN</parameter></methodparam> <methodparam><type>int</type><parameter>colno</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam><type>int</type><parameter>PDO::FETCH_CLASS</parameter></methodparam> <methodparam><type>string</type><parameter>classname</parameter></methodparam> <methodparam><type>array</type><parameter>ctorargs</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam><type>int</type><parameter>PDO::FETCH_INTO</parameter></methodparam> <methodparam><type>object</type><parameter>object</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDO-query" /> executes an SQL statement in a single function call, returning the result set (if any) returned by the statement as a PDOStatement object. </para> <para> For a query that you need to issue multiple times, you will realize better performance if you prepare a PDOStatement object using <xref linkend="function.PDO-prepare" /> and issue the statement with multiple calls to <xref linkend="function.PDOStatement-execute" />. </para> <para> If you do not fetch all of the data in a result set before issuing your next call to <xref linkend="function.PDO-query" />, your call may fail. Call <xref linkend="function.PDOStatement-closeCursor" /> to release the database resources associated with the PDOStatement object before issuing your next call to <xref linkend="function.PDO-query" />. </para> <note> <para> Although this function is only documented as having a single parameter, you may pass additional arguments to this function. They will be treated as though you called <xref linkend="function.PDOStatement-setFetchMode" /> on the resultant statement object. </para> </note> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>statement</parameter></term> <listitem> <para> The SQL statement to prepare and execute. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-query" /> returns a PDOStatement object. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Demonstrate PDO::query</title> <para> A nice feature of <xref linkend="function.PDO-query" /> is that it enables you to iterate over the rowset returned by a successfully executed SELECT statement. </para> <programlisting role="php"> <![CDATA[ <?php function getFruit($conn) { $sql = 'SELECT name, colour, calories FROM fruit ORDER BY name'; foreach ($conn->query($sql) as $row) { print $row['NAME'] . "\t"; print $row['COLOUR'] . "\t"; print $row['CALORIES'] . "\n"; } } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple red 150 banana yellow 250 kiwi brown 75 lemon yellow 25 orange orange 300 pear green 150 watermelon pink 90 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-exec" /></member> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/quote.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/quote.xml +++ phpdoc/en/reference/pdo/pdo/quote.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-quote" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->quote()</refname> <refpurpose> Quotes a string for use in a query. </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>string</type><methodname>quote</methodname> <methodparam><type>string</type><parameter>string</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>parameter_type</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDO-quote" /> places quotes around the input string (if required) and escapes special characters within the input string, using a quoting style appropriate to the underlying driver. </para> <para> If you are using this function to build SQL statements, you are <emphasis>strongly</emphasis> recommended to use <xref linkend="function.PDO-prepare" /> to prepare SQL statements with bound parameters instead of using <xref linkend="function.PDO-quote" /> to interpolate user input into a SQL statement. Prepared statements with bound parameters are not only more portable, more convenient, immune to SQL injection, but are often much faster to execute than interpolated queries, as both the server and client side can cache a compiled form of the query. </para> <para> Not all PDO drivers implement this method (notably PDO_ODBC). Consider using prepared statements instead. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>string</parameter></term> <listitem> <para> The string to be quoted. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>parameter_type</parameter></term> <listitem> <para> Provides a data type hint for drivers that have alternate quoting styles. The default value is PDO::PARAM_STR. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns a quoted string that is theoretically safe to pass into an SQL statement. Returns &false; if the driver does not support quoting in this way. </para> </refsect1> <!-- Use when ERRORS exist <refsect1 role="errors"> &reftitle.errors; <para> When does this function throw E_* level errors, or exceptions? </para> </refsect1> --> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Quoting a normal string</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('sqlite:/home/lynn/music.sql3'); /* Simple string */ $string = 'Nice'; print "Unquoted string: $string\n"; print "Quoted string: " . $conn->quote($string) . "\n"; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Unquoted string: Nice Quoted string: 'Nice' ]]> </screen> </example> <example> <title>Quoting a dangerous string</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('sqlite:/home/lynn/music.sql3'); /* Dangerous string */ $string = 'Naughty \' string'; print "Unquoted string: $string\n"; print "Quoted string:" . $conn->quote($string) . "\n"; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Unquoted string: Naughty ' string Quoted string: 'Naughty '' string' ]]> </screen> </example> <example> <title>Quoting a complex string</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('sqlite:/home/lynn/music.sql3'); /* Complex string */ $string = "Co'mpl''ex \"st'\"ring"; print "Unquoted string: $string\n"; print "Quoted string: " . $conn->quote($string) . "\n"; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Unquoted string: Co'mpl''ex "st'"ring Quoted string: 'Co''mpl''''ex "st''"ring' ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/rollback.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/rollback.xml +++ phpdoc/en/reference/pdo/pdo/rollback.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-rollBack" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->rollBack()</refname> <refpurpose> Rolls back a transaction </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>rollBack</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Rolls back the current transaction, as initiated by <xref linkend="function.PDO-beginTransaction" />. It is an error to call this method if no transaction is active. </para> <para> If the database was set to autocommit mode, this function will restore autocommit mode after it has rolled back the transaction. </para> <para> Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Roll back a transaction</title> <para> The following example begins a transaction and issues two statements that modify the database before rolling back the changes. On MySQL, however, the DROP TABLE statement automatically commits the transaction so that none of the changes in the transaction are rolled back. </para> <programlisting role='php'> <![CDATA[ <?php /* Begin a transaction, turning off autocommit */ $dbh->beginTransaction(); /* Change the database schema and data */ $sth = $dbh->exec("DROP TABLE fruit"); $sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'"); /* Recognize mistake and roll back changes */ $dbh->rollBack(); /* Database connection is now back in autocommit mode */ ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-beginTransaction" /></member> <member><xref linkend="function.PDO-commit" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/setattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/setattribute.xml +++ phpdoc/en/reference/pdo/pdo/setattribute.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-setAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->setAttribute()</refname> <refpurpose> Set an attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> <methodparam><type>mixed</type><parameter>value</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Sets an attribute on the database handle. Some of the available generic attributes are listed below; some drivers may make use of additional driver specific attributes. <itemizedlist> <listitem><para> <literal>PDO::ATTR_CASE</literal>: Force column names to a specific case. <itemizedlist> <listitem><para> <literal>PDO::CASE_LOWER</literal>: Force column names to lower case. </para></listitem> <listitem><para> <literal>PDO::CASE_NATURAL</literal>: Leave column names as returned by the database driver. </para></listitem> <listitem><para> <literal>PDO::CASE_UPPER</literal>: Force column names to upper case. </para></listitem> </itemizedlist> </para></listitem> <listitem><para><literal>PDO::ATTR_ERRMODE</literal>: Error reporting. <itemizedlist> <listitem><para><literal>PDO::ERRMODE_SILENT</literal>: Just set error codes.</para></listitem> <listitem><para><literal>PDO::ERRMODE_WARNING</literal>: Raise <link linkend="errorfunc.constants.errorlevels.e-warning">E_WARNING</link>.</para></listitem> <listitem><para><literal>PDO::ERRMODE_EXCEPTION</literal>: Throw <link linkend="language.exceptions">exceptions</link>.</para></listitem> </itemizedlist> </para></listitem> <listitem><para><literal>PDO::ATTR_ORACLE_NULLS</literal> (available with all drivers, not just Oracle): Conversion of NULL and empty strings. <itemizedlist> <listitem><para><literal>PDO::NULL_NATURAL</literal>: No conversion.</para></listitem> <listitem><para><literal>PDO::NULL_EMPTY_STRING</literal>: Empty string is converted to &null;.</para></listitem> <listitem><para><literal>PDO::NULL_TO_STRING</literal>: NULL is converted to an empty string.</para></listitem> </itemizedlist> </para></listitem> <listitem><para><literal>PDO::ATTR_STRINGIFY_FETCHES</literal>: Convert numeric values to strings when fetching. Requires <type>bool</type>. </para></listitem> <listitem><para><literal>PDO::ATTR_STATEMENT_CLASS</literal>: Set user-supplied statement class derived from PDOStatement. Cannot be used with persistent PDO instances. Requires <literal>array(string classname, array(mixed constructor_args))</literal>. </para></listitem> <listitem><para><literal>PDO::ATTR_AUTOCOMMIT</literal> (available in OCI, Firebird and MySQL): Whether to autocommit every single statement. </para></listitem> <listitem><para><literal>PDO::MYSQL_ATTR_USE_BUFFERED_QUERY</literal> (available in MySQL): Use buffered queries. </para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/bindcolumn.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/bindcolumn.xml +++ phpdoc/en/reference/pdo/pdostatement/bindcolumn.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-bindColumn" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->bindColumn()</refname> <refpurpose> Bind a column to a PHP variable </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>bindColumn</methodname> <methodparam><type>mixed</type><parameter>column</parameter></methodparam> <methodparam><type>mixed</type><parameter role="reference">param</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>type</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDOStatement-bindColumn" /> arranges to have a particular variable bound to a given column in the result-set from a query. Each call to <xref linkend="function.PDOStatement-fetch" /> or <xref linkend="function.PDOStatement-fetchAll" /> will update all the variables that are bound to columns. </para> <note> <para> Since information about the columns is not always available to PDO until the statement is executed, portable applications should call this function <emphasis>after</emphasis> <xref linkend="function.PDOStatement-execute" />. </para> </note> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>column</parameter></term> <listitem> <para> Number of the column (1-indexed) or name of the column in the result set. If using the column name, be aware that the name should match the case of the column, as returned by the driver. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>param</parameter></term> <listitem> <para> Name of the PHP variable to which the column will be bound. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>type</parameter></term> <listitem> <para> Data type of the parameter, specified by the PDO::PARAM_* constants. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Binding result set output to PHP variables</title> <para> Binding columns in the result set to PHP variables is an effective way to make the data contained in each row immediately available to your application. The following example demonstrates how PDO allows you to bind and retrieve columns with a variety of options and with intelligent defaults. </para> <programlisting role="php"> <![CDATA[ <?php function readData($dbh) { $sql = 'SELECT name, colour, calories FROM fruit'; try { $stmt = $dbh->prepare($sql); $stmt->execute(); /* Bind by column number */ $stmt->bindColumn(1, $name); $stmt->bindColumn(2, $colour); /* Bind by column name */ $stmt->bindColumn('calories', $cals); while ($row = $stmt->fetch(PDO::FETCH_BOUND)) { $data = $name . "\t" . $colour . "\t" . $cals . "\n"; print $data; } } catch (PDOException $e) { print $e->getMessage(); } } readData($dbh); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple red 150 banana yellow 175 kiwi green 75 orange orange 150 mango red 200 strawberry red 25 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/bindparam.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/bindparam.xml +++ phpdoc/en/reference/pdo/pdostatement/bindparam.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-bindParam" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->bindParam()</refname> <refpurpose> Binds a parameter to the specified variable name </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>bindParam</methodname> <methodparam><type>mixed</type><parameter>parameter</parameter></methodparam> <methodparam><type>mixed</type><parameter role="reference">variable</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>data_type</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam> <methodparam choice="opt"><type>mixed</type><parameter>driver_options</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Binds a PHP variable to a corresponding named or question mark placeholder in the SQL statement that was use to prepare the statement. Unlike <xref linkend="function.PDOStatement-bindValue" />, the variable is bound as a reference and will only be evaluated at the time that <xref linkend="function.PDOStatement-execute" /> is called. </para> <para> Most parameters are input parameters, that is, parameters that are used in a read-only fashion to build up the query. Some drivers support the invocation of stored procedures that return data as output parameters, and some also as input/output parameters that both send in data and are updated to receive it. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>parameter</parameter></term> <listitem> <para> Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form <varname>:name</varname>. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>variable</parameter></term> <listitem> <para> Name of the PHP variable to bind to the SQL statement parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>data_type</parameter></term> <listitem> <para> Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PHP native type. To return an INOUT parameter from a stored procedure, use the bitwise OR operator to set the PDO::PARAM_INPUT_OUTPUT bits for the <parameter>data_type</parameter> parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>length</parameter></term> <listitem> <para> Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>driver_options</parameter></term> <listitem> <para> </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example><title>Execute a prepared statement with named placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute(); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with question mark placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* 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>Pass a NULL value into a prepared statement</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); /* Find fruit with a NULL value in the colour column */ $sth->bindParam(':colour', $colour, PDO::PARAM_NULL); $sth->execute(); ?> ]]> </programlisting> </example> --> <example><title>Call a stored procedure with an INOUT parameter</title> <programlisting role='php'> <![CDATA[ <?php /* Call a stored procedure with an INOUT parameter */ $colour = 'red'; $sth = $dbh->prepare('CALL puree_fruit(?)'); $sth->bindParam(1, $colour, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 12); $sth->execute(); print("After pureeing fruit, the colour is: $colour"); ?> ]]> </programlisting> </example> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-bindValue" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/bindvalue.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/bindvalue.xml +++ phpdoc/en/reference/pdo/pdostatement/bindvalue.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-bindValue" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->bindValue()</refname> <refpurpose> Binds a value to a parameter </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>bindValue</methodname> <methodparam><type>mixed</type><parameter>parameter</parameter></methodparam> <methodparam><type>mixed</type><parameter>value</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>data_type</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Binds a value to a corresponding named or question mark placeholder in the SQL statement that was use to prepare the statement. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>parameter</parameter></term> <listitem> <para> Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form <varname>:name</varname>. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>value</parameter></term> <listitem> <para> The value to bind to the parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>data_type</parameter></term> <listitem> <para> Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PHP native type. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example><title>Execute a prepared statement with named placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindValue(':calories', $calories, PDO::PARAM_INT); $sth->bindValue(':colour', $colour, PDO::PARAM_STR); $sth->execute(); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with question mark placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* 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->bindValue(1, $calories, PDO::PARAM_INT); $sth->bindValue(2, $colour, PDO::PARAM_STR); $sth->execute(); ?> ]]> </programlisting> </example> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-bindParam" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/closecursor.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/closecursor.xml +++ phpdoc/en/reference/pdo/pdostatement/closecursor.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-closeCursor" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->closeCursor()</refname> <refpurpose> Closes the cursor, enabling the statement to be executed again. </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>closeCursor</methodname> <void/> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDOStatement-closeCursor" /> frees up the connection to the server so that other SQL statements may be issued, but leaves the statement in a state that enables it to be executed again. </para> <para> This method is useful for database drivers that do not support executing a PDOStatement object when a previously executed PDOStatement object still has unfetched rows. If your database driver suffers from this limitation, the problem may manifest itself in an out-of-sequence error. </para> <para> <xref linkend="function.PDOStatement-closeCursor" /> is implemented either as an optional driver specific method (allowing for maximum efficiency), or as the generic PDO fallback if no driver specific function is installed. The PDO generic fallback is semantically the same as writing the following code in your PHP script: <programlisting role="php"> <![CDATA[ <?php do { while ($stmt->fetch()) ; if (!$stmt->nextRowset()) break; } while (true); ?> ]]> </programlisting> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>A <xref linkend="function.PDOStatement-closeCursor" /> example</title> <para> In the following example, the <varname>$stmt</varname> PDOStatement object returns multiple rows but the application fetches only the first row, leaving the PDOStatement object in a state of having unfetched rows. To ensure that the application will work with all database drivers, the author inserts a call to <xref linkend="function.PDOStatement-closeCursor" /> on <varname>$stmt</varname> before executing the <varname>$otherStmt</varname> PDOStatement object. </para> <programlisting role="php"> <![CDATA[ <?php /* Create a PDOStatement object */ $stmt = $dbh->prepare('SELECT foo FROM bar'); /* Create a second PDOStatement object */ $otherStmt = $dbh->prepare('SELECT foobaz FROM foobar'); /* Execute the first statement */ $stmt->execute(); /* Fetch only the first row from the results */ $stmt->fetch(); /* The following call to closeCursor() may be required by some drivers */ $stmt->closeCursor(); /* Now we can execute the second statement */ $otherStmt->execute(); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/columncount.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/columncount.xml +++ phpdoc/en/reference/pdo/pdostatement/columncount.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-columnCount" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->columnCount()</refname> <refpurpose> Returns the number of columns in the result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>int</type><methodname>columnCount</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Use <xref linkend="function.PDOStatement-columnCount" /> to return the number of columns in the result set represented by the PDOStatement object. </para> <para> If the PDOStatement object was returned from <xref linkend="function.PDO-query" />, the column count is immediately available. </para> <para> If the PDOStatement object was returned from <xref linkend="function.PDO-prepare" />, an accurate column count will not be available until you invoke <xref linkend="function.PDOStatement-execute" />. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns the number of columns in the result set represented by the PDOStatement object. If there is no result set, <xref linkend="function.PDOStatement-columnCount" /> returns <literal>0</literal>. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Counting columns</title> <para> This example demonstrates how <xref linkend="function.PDOStatement-columnCount" /> operates with and without a result set. </para> <programlisting role="php"> <![CDATA[ <?php $dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); $sth = $dbh->prepare("SELECT name, colour FROM fruit"); /* Count the number of columns in the (non-existent) result set */ $colcount = $sth->columnCount(); print("Before execute(), result set has $colcount columns (should be 0)\n"); $sth->execute(); /* Count the number of columns in the result set */ $colcount = $sth->columnCount(); print("After execute(), result set has $colcount columns (should be 2)\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Before execute(), result set has 0 columns (should be 0) After execute(), result set has 2 columns (should be 2) ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-rowCount" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/errorcode.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/errorcode.xml +++ phpdoc/en/reference/pdo/pdostatement/errorcode.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-errorCode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->errorCode()</refname> <refpurpose> Fetch the SQLSTATE associated with the last operation on the statement handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>string</type><methodname>errorCode</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Identical to <xref linkend="function.PDO-errorCode" />, except that <xref linkend="function.PDOStatement-errorCode" /> only retrieves error codes for operations performed with PDOStatement objects. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Retrieving a SQLSTATE code</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- the BONES table does not exist */ $err = $dbh->prepare('SELECT skull FROM bones'); $err->execute(); echo "\nPDOStatement::errorCode(): "; print $err->errorCode(); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDOStatement::errorCode(): 42S02 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorCode" /></member> <member><xref linkend="function.PDO-errorInfo" /></member> <member><xref linkend="function.PDOStatement-errorInfo" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/errorinfo.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/errorinfo.xml +++ phpdoc/en/reference/pdo/pdostatement/errorinfo.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-errorInfo" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->errorInfo()</refname> <refpurpose> Fetch extended error information associated with the last operation on the statement handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>array</type><methodname>errorInfo</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDOStatement-errorInfo" /> returns an array of error information about the last operation performed by this statement handle. The array consists of the following fields: <informaltable> <tgroup cols='2'> <thead> <row> <entry>Element</entry> <entry>Information</entry> </row> </thead> <tbody> <row> <entry>0</entry> <entry>SQLSTATE error code (a five-character alphanumeric identifier defined in the ANSI SQL standard).</entry> </row> <row> <entry>1</entry> <entry>Driver-specific error code.</entry> </row> <row> <entry>2</entry> <entry>Driver-specific error message.</entry> </row> </tbody> </tgroup> </informaltable> </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Displaying errorInfo() fields for a PDO_ODBC connection to a DB2 database</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- the BONES table does not exist */ $sth = $dbh->prepare('SELECT skull FROM bones'); $sth->execute(); echo "\nPDOStatement::errorInfo():\n"; $arr = $sth->errorInfo(); print_r($arr); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDOStatement::errorInfo(): Array ( [0] => 42S02 [1] => -204 [2] => [IBM][CLI Driver][DB2/LINUX] SQL0204N "DANIELS.BONES" is an undefined name. SQLSTATE=42704 ) ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorCode" /></member> <member><xref linkend="function.PDO-errorInfo" /></member> <member><xref linkend="function.PDOStatement-errorCode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/execute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/execute.xml +++ phpdoc/en/reference/pdo/pdostatement/execute.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-execute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->execute()</refname> <refpurpose> Executes a prepared statement </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>execute</methodname> <methodparam choice="opt"><type>array</type><parameter>input_parameters</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Execute the prepared statement. If the prepared statement included parameter markers, you must either: <itemizedlist> <listitem><para>call <xref linkend="function.PDOStatement-bindParam" /> 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 input-only parameter values</para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>input_parameters</parameter></term> <listitem> <para> An array of values with as many elements as there are bound parameters in the SQL statement being executed. </para> <para> You cannot bind multiple values to a single parameter; for example, you cannot bind two values to a single named parameter in an IN() clause. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example><title>Execute a prepared statement with bound variables</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute(); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with an array of insert values (named parameters)</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by passing an array of insert values */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->execute(array(':calories' => $calories, ':colour' => $colour)); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with an array of insert values (placeholders)</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by passing an array of insert values */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ?'); $sth->execute(array($calories, $colour)); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with question mark placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* 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> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-bindParam" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetch.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetch.xml +++ phpdoc/en/reference/pdo/pdostatement/fetch.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetch" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetch()</refname> <refpurpose> Fetches the next row from a result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>fetch</methodname> <methodparam choice="opt"><type>int</type><parameter>fetch_style</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>cursor_orientation</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>cursor_offset</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Fetches a row from a result set associated with a PDOStatement object. The <parameter>fetch_style</parameter> parameter determines how PDO returns the row. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>fetch_style</parameter></term> <listitem> <para> Controls how the next row will be returned to the caller. This value must be one of the <literal>PDO::FETCH_*</literal> constants, defaulting to <literal>PDO::FETCH_BOTH</literal>. <itemizedlist> <listitem><para> <literal>PDO::FETCH_ASSOC</literal>: returns an array indexed by column name as returned in your result set </para></listitem> <listitem><para> <literal>PDO::FETCH_BOTH</literal> (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set </para></listitem> <listitem><para> <literal>PDO::FETCH_BOUND</literal>: returns &true; and assigns the values of the columns in your result set to the PHP variables to which they were bound with the <xref linkend="function.PDOStatement-bindColumn" /> method </para></listitem> <listitem><para> <literal>PDO::FETCH_CLASS</literal>: returns a new instance of the requested class, mapping the columns of the result set to named properties in the class. If <parameter>fetch_style</parameter> includes PDO::FETCH_CLASSTYPE (e.g. <literal>PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE</literal>) then the name of the class is determined from a value of the first column. </para></listitem> <listitem><para> <literal>PDO::FETCH_INTO</literal>: updates an existing instance of the requested class, mapping the columns of the result set to named properties in the class </para></listitem> <listitem><para> <literal>PDO::FETCH_LAZY</literal>: combines <literal>PDO::FETCH_BOTH</literal> and <literal>PDO::FETCH_OBJ</literal>, creating the object variable names as they are accessed </para></listitem> <listitem><para> <literal>PDO::FETCH_NUM</literal>: returns an array indexed by column number as returned in your result set, starting at column 0 </para></listitem> <listitem><para> <literal>PDO::FETCH_OBJ</literal>: returns an anonymous object with property names that correspond to the column names returned in your result set </para></listitem> </itemizedlist> </para> </listitem> </varlistentry> <varlistentry> <term><parameter>cursor_orientation</parameter></term> <listitem> <para> For a PDOStatement object representing a scrollable cursor, this value determines which row will be returned to the caller. This value must be one of the <literal>PDO::FETCH_ORI_*</literal> constants, defaulting to <literal>PDO::FETCH_ORI_NEXT</literal>. To request a scrollable cursor for your PDOStatement object, you must set the <literal>PDO::ATTR_CURSOR</literal> attribute to <literal>PDO::CURSOR_SCROLL</literal> when you prepare the SQL statement with <xref linkend="function.PDO-prepare" />. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>offset</parameter></term> <listitem> <para> For a PDOStatement object representing a scrollable cursor for which the <literal>cursor_orientation</literal> parameter is set to <literal>PDO::FETCH_ORI_ABS</literal>, this value specifies the absolute number of the row in the result set that shall be fetched. </para> <para> For a PDOStatement object representing a scrollable cursor for which the <literal>cursor_orientation</literal> parameter is set to <literal>PDO::FETCH_ORI_REL</literal>, this value specifies the row to fetch relative to the cursor position before <xref linkend="function.PDOStatement-fetch" /> was called. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> The return value of this function on success depends on the fetch type. In all cases, &false; is returned on failure. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Fetching rows using different fetch styles</title> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Exercise PDOStatement::fetch styles */ print("PDO::FETCH_ASSOC: "); print("Return next row as an array indexed by column name\n"); $result = $sth->fetch(PDO::FETCH_ASSOC); print_r($result); print("\n"); print("PDO::FETCH_BOTH: "); print("Return next row as an array indexed by both column name and number\n"); $result = $sth->fetch(PDO::FETCH_BOTH); print_r($result); print("\n"); print("PDO::FETCH_LAZY: "); print("Return next row as an anonymous object with column names as properties\n"); $result = $sth->fetch(PDO::FETCH_LAZY); print_r($result); print("\n"); print("PDO::FETCH_OBJ: "); print("Return next row as an anonymous object with column names as properties\n"); $result = $sth->fetch(PDO::FETCH_OBJ); print $result->NAME; print("\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDO::FETCH_ASSOC: Return next row as an array indexed by column name Array ( [NAME] => apple [COLOUR] => red ) PDO::FETCH_BOTH: Return next row as an array indexed by both column name and number Array ( [NAME] => banana [0] => banana [COLOUR] => yellow [1] => yellow ) PDO::FETCH_LAZY: Return next row as an anonymous object with column names as properties PDORow Object ( [NAME] => orange [COLOUR] => orange ) PDO::FETCH_OBJ: Return next row as an anonymous object with column names as properties kiwi ]]> </screen> </example> <example><title>Fetching rows with a scrollable cursor</title> <programlisting role="php"> <![CDATA[ <?php function readDataForwards($dbh) { $sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY BET'; try { $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; print $data; } $stmt = null; } catch (PDOException $e) { print $e->getMessage(); } } function readDataBackwards($dbh) { $sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY bet'; try { $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST); do { $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; print $data; } while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR)); $stmt = null; } catch (PDOException $e) { print $e->getMessage(); } } print "Reading forwards:\n"; readDataForwards($conn); print "Reading backwards:\n"; readDataBackwards($conn); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Reading forwards: 21 10 5 16 0 5 19 20 10 Reading backwards: 19 20 10 16 0 5 21 10 5 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> <member><xref linkend="function.PDOStatement-fetchObject" /></member> <member><xref linkend="function.PDOStatement-setFetchMode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetchall.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetchall.xml +++ phpdoc/en/reference/pdo/pdostatement/fetchall.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetchAll" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetchAll()</refname> <refpurpose> Returns an array containing all of the result set rows </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>array</type><methodname>fetchAll</methodname> <methodparam choice="opt"><type>int</type><parameter>fetch_style</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>column_index</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>ctor_args</parameter></methodparam> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>fetch_style</parameter></term> <listitem> <para> Controls the contents of the returned array as documented in <xref linkend="function.PDOStatement-fetch" />. Defaults to <literal>PDO::FETCH_BOTH</literal>. </para> <para> To return an array consisting of all values of a single column from the result set, specify <literal>PDO::FETCH_COLUMN</literal>. You can specify which column you want with the <parameter>column-index</parameter> parameter. </para> <para> To fetch only the unique values of a single column from the result set, bitwise-OR <literal>PDO::FETCH_COLUMN</literal> with <literal>PDO::FETCH_UNIQUE</literal>. </para> <para> To return an associative array grouped by the values of a specified column, bitwise-OR <literal>PDO::FETCH_COLUMN</literal> with <literal>PDO::FETCH_GROUP</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>column_index</parameter></term> <listitem> <para> Returns the indicated 0-indexed column when the value of <parameter>fetch_style</parameter> is <literal>PDO::FETCH_COLUMN</literal>. Defaults to <literal>0</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>ctor_args</parameter></term> <listitem> <para> Arguments of custom class constructor. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDOStatement-fetchAll" /> returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties corresponding to each column name. </para> <para> Using this method to fetch large result sets will result in a heavy demand on system and possibly network resources. Rather than retrieving all of the data and manipulating it in PHP, consider using the database server to manipulate the result sets. For example, use the WHERE and SORT BY clauses in SQL to restrict results before retrieving and processing them with PHP. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Fetch all remaining rows in a result set</title> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch all of the remaining rows in the result set */ print("Fetch all of the remaining rows in the result set:\n"); $result = $sth->fetchAll(); print_r($result); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Fetch all of the remaining rows in the result set: Array ( [0] => Array ( [NAME] => pear [0] => pear [COLOUR] => green [1] => green ) [1] => Array ( [NAME] => watermelon [0] => watermelon [COLOUR] => pink [1] => pink ) ) ]]> </screen> </example> <example><title>Fetching all values of a single column from a result set</title> <para> The following example demonstrates how to return all of the values of a single column from a result set, even though the SQL statement itself may return multiple columns per row. </para> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch all of the values of the first column */ $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0); var_dump($result); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Array(3) ( [0] => string(5) => apple [1] => string(4) => pear [2] => string(10) => watermelon ) ]]> </screen> </example> <example><title>Grouping all values by a single column</title> <para> The following example demonstrates how to return an associative array grouped by the values of the specified column in the result set. The array contains three keys: values <literal>apple</literal> and <literal>pear</literal> are returned as arrays that contain two different colours, while <literal>watermelon</literal> is returned as an array that contains only one colour. </para> <programlisting role="php"> <![CDATA[ <?php $insert = $dbh->prepare("INSERT INTO fruit(name, colour) VALUES (?, ?)"); $insert->execute('apple', 'green'); $insert->execute('pear', 'yellow'); $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Group values by the first column */ var_dump($sth->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP)); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ array(3) { ["apple"]=> array(2) { [0]=> string(5) "green" [1]=> string(3) "red" } ["pear"]=> array(2) { [0]=> string(5) "green" [1]=> string(6) "yellow" } ["watermelon"]=> array(1) { [0]=> string(5) "green" } } ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-setFetchMode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetchcolumn.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetchcolumn.xml +++ phpdoc/en/reference/pdo/pdostatement/fetchcolumn.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetchColumn" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetchColumn()</refname> <refpurpose> Returns a single column from the next row of a result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>string</type><methodname>fetchColumn</methodname> <methodparam choice="opt"><type>int</type><parameter>column_number</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Returns a single column from the next row of a result set or &false; if there are no more rows. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>column_number</parameter></term> <listitem> <para> 0-indexed number of the column you wish to retrieve from the row. If no value is supplied, <xref linkend="function.PDOStatement-fetchColumn" /> fetches the first column. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDOStatement-fetchColumn" /> returns a single column in the next row of a result set. </para> <warning> <para> There is no way to return another column from the same row if you use <xref linkend="function.PDOStatement-fetchColumn" /> to retrieve data. </para> </warning> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Return first column of the next row</title> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch the first column from the next row in the result set */ print("Fetch the first column from the next row in the result set:\n"); $result = $sth->fetchColumn(); print("name = $result\n"); print("Fetch the second column from the next row in the result set:\n"); $result = $sth->fetchColumn(1); print("colour = $result\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Fetch the first column from the next row in the result set: name = lemon Fetch the second column from the next row in the result set: colour = red ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-setFetchMode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetchobject.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetchobject.xml +++ phpdoc/en/reference/pdo/pdostatement/fetchobject.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetchObject" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetchObject()</refname> <refpurpose>Fetches the next row and returns it as an object.</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>fetchObject</methodname> <methodparam choice="opt"><type>string</type><parameter>class_name</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>ctor_args</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Fetches the next row and returns it as an object. This function is an alternative to <xref linkend="function.PDOStatement-fetch" /> with <constant>PDO::FETCH_CLASS</constant> or <constant>PDO::FETCH_OBJ</constant> style. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>class_name</parameter></term> <listitem> <para> Name of the created class, defaults to <literal>stdClass</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>ctor_args</parameter></term> <listitem> <para> Elements of this array are passed to the constructor. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns an instance of the required class with property names that correspond to the column names or &false; in case of an error. </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-fetch" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/getattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/getattribute.xml +++ phpdoc/en/reference/pdo/pdostatement/getattribute.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-getAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->getAttribute()</refname> <refpurpose> Retrieve a statement attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>getAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Gets an attribute of the statement. Currently, no generic attributes exist but only driver specific: <itemizedlist> <listitem><para><literal>PDO::ATTR_CURSOR_NAME</literal> (Firebird and ODBC specific): Get the name of cursor for <literal>UPDATE ... WHERE CURRENT OF</literal>. </para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns the attribute value. </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-getAttribute" /></member> <member><xref linkend="function.PDO-setAttribute" /></member> <member><xref linkend="function.PDOStatement-setAttribute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/getcolumnmeta.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/getcolumnmeta.xml +++ phpdoc/en/reference/pdo/pdostatement/getcolumnmeta.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-getColumnMeta" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->getColumnMeta()</refname> <refpurpose> Returns metadata for a column in a result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>array</type><methodname>getColumnMeta</methodname> <methodparam><type>int</type><parameter>column</parameter></methodparam> </methodsynopsis> </classsynopsis> &warn.experimental.func; <para> Retrieves the metadata for a 0-indexed column in a result set as an associative array. </para> <warning> <simpara> Not all PDO drivers support <xref linkend="function.PDOStatement-getColumnMeta" />. </simpara> </warning> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>column</parameter></term> <listitem> <para> The 0-indexed column in the result set. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns an associative array containing the following values representing the metadata for a single column: </para> <table> <title>Column metadata</title> <tgroup cols='2'> <colspec colname='c1'/> <colspec colname='c2'/> <thead> <row> <entry>Name</entry> <entry>Value</entry> </row> </thead> <tbody> <row> <entry><literal>native_type</literal></entry> <entry>The PHP native type used to represent the column value.</entry> </row> <row> <entry><literal>driver:decl_type</literal></entry> <entry>The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by <xref linkend="function.PDOStatement-getColumnMeta" />. </entry> </row> <row> <entry><literal>flags</literal></entry> <entry>Any flags set for this column.</entry> </row> <row> <entry><literal>name</literal></entry> <entry>The name of this column as returned by the database.</entry> </row> <row> <entry><literal>table</literal></entry> <entry>The name of this column's table as returned by the database.</entry> </row> <row> <entry><literal>len</literal></entry> <entry>The length of this column. Normally <literal>-1</literal> for types other than floating point decimals.</entry> </row> <row> <entry><literal>precision</literal></entry> <entry>The numeric precision of this column. Normally <literal>0</literal> for types other than floating point decimals.</entry> </row> <row> <entry><literal>pdo_type</literal></entry> <entry>The type of this column as represented by the <literal>PDO::PARAM_*</literal> constants.</entry> </row> </tbody> </tgroup> </table> <para> Returns &false; if the requested column does not exist in the result set, or if no result set exists. </para> </refsect1> <!-- Use when ERRORS exist <refsect1 role="errors"> &reftitle.errors; <para> When does this function throw E_* level errors, or exceptions? </para> </refsect1> --> <refsect1 role="changelog"> &reftitle.changelog; <para> <informaltable> <tgroup cols="2"> <thead> <row> <entry>&Version;</entry> <entry>&Description;</entry> </row> </thead> <tbody> <row> <entry>5.2.3</entry> <entry><literal>table</literal> field</entry> </row> </tbody> </tgroup> </informaltable> </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Retrieving column metadata</title> <para> The following example shows the results of retrieving the metadata for a single column generated by a function (COUNT) in a PDO_SQLITE driver. </para> <programlisting role="php"> <![CDATA[ <?php $select = $DB->query('SELECT COUNT(*) FROM fruit'); $meta = $select->getColumnMeta(0); var_dump($meta); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ array(6) { ["native_type"]=> string(7) "integer" ["flags"]=> array(0) { } ["name"]=> string(8) "COUNT(*)" ["len"]=> int(-1) ["precision"]=> int(0) ["pdo_type"]=> int(2) } ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-columnCount" /></member> <member><xref linkend="function.PDOStatement-rowCount" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/nextrowset.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/nextrowset.xml +++ phpdoc/en/reference/pdo/pdostatement/nextrowset.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-nextRowset" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->nextRowset()</refname> <refpurpose> Advances to the next rowset in a multi-rowset statement handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>nextRowset</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Some database servers support stored procedures that return more than one rowset (also known as a result set). <xref linkend="function.PDOStatement-nextRowset" /> enables you to access the second and subsequent rowsets associated with a PDOStatement object. Each rowset can have a different set of columns from the preceding rowset. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Fetching multiple rowsets returned from a stored procedure</title> <para> The following example shows how to call a stored procedure, MULTIPLE_ROWSETS, that returns three rowsets. We use a do / while loop to loop over the <xref linkend="function.PDOStatement-nextRowset" /> method, which returns false and terminates the loop when no more rowsets can be returned. </para> <programlisting role="php"> <![CDATA[ <?php $sql = 'CALL multiple_rowsets()'; $stmt = $conn->query($sql); $i = 1; do { $rowset = $stmt->fetch(PDO::FETCH_NUM); if ($rowset) { printResultSet($rowset, $i); } $i++; } while ($stmt->nextRowset()); function printResultSet(&$rowset, $i) { print "Result set $i:\n"; foreach ($rowset as $row) { foreach ($row as $col) { print $col . "\t"; } print "\n"; } print "\n"; } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Result set 1: apple red banana yellow Result set 2: orange orange 150 banana yellow 175 Result set 3: lime green apple red banana yellow ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-columnCount" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-getColumnMeta" /></member> <member><xref linkend="function.PDO-query" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/rowcount.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/rowcount.xml +++ phpdoc/en/reference/pdo/pdostatement/rowcount.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-rowCount" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->rowCount()</refname> <refpurpose> Returns the number of rows affected by the last SQL statement </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>int</type><methodname>rowCount</methodname> <void/> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDOStatement-rowCount" /> returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding <literal>PDOStatement</literal> object. </para> <para> If the last SQL statement executed by the associated <literal>PDOStatement</literal> was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns the number of rows. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Return the number of deleted rows</title> <para> <xref linkend="function.PDOStatement-rowCount" /> returns the number of rows affected by a DELETE, INSERT, or UPDATE statement. </para> <programlisting role="php"> <![CDATA[ <?php /* Delete all rows from the FRUIT table */ $del = $dbh->prepare('DELETE FROM fruit'); $del->execute(); /* Return number of rows that were deleted */ print("Return number of rows that were deleted:\n"); $count = $del->rowCount(); print("Deleted $count rows.\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Deleted 9 rows. ]]> </screen> </example> <example> <title>Counting rows returned by a SELECT statement</title> <para> For most databases, <xref linkend="function.PDOStatement-rowCount" /> does not return the number of rows affected by a SELECT statement. Instead, use <xref linkend="function.PDO-query" /> to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use <xref linkend="function.PDOStatement-fetchColumn" /> to retrieve the number of rows that will be returned. Your application can then perform the correct action. </para> <programlisting role="php"> <![CDATA[ <?php $sql = "SELECT COUNT(*) FROM fruit WHERE calories > 100"; if ($res = $conn->query($sql)) { /* Check the number of rows that match the SELECT statement */ if ($res->fetchColumn() > 0) { /* Issue the real SELECT statement and work with the results */ $sql = "SELECT name FROM fruit WHERE calories > 100"; foreach ($conn->query($sql) as $row) { print "Name: " . $row['NAME'] . "\n"; } } /* No rows matched -- do something else */ else { print "No rows matched the query."; } } $res = null; $conn = null; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple banana orange pear ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-columnCount" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> <member><xref linkend="function.PDO-query" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/setattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/setattribute.xml +++ phpdoc/en/reference/pdo/pdostatement/setattribute.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-setAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->setAttribute()</refname> <refpurpose> Set a statement attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> <methodparam><type>mixed</type><parameter>value</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Sets an attribute on the statement. Currently, no generic attributes are set but only driver specific: <itemizedlist> <listitem><para><literal>PDO::ATTR_CURSOR_NAME</literal> (Firebird and ODBC specific): Set the name of cursor for <literal>UPDATE ... WHERE CURRENT OF</literal>. </para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-getAttribute" /></member> <member><xref linkend="function.PDO-setAttribute" /></member> <member><xref linkend="function.PDOStatement-getAttribute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/setfetchmode.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/setfetchmode.xml +++ phpdoc/en/reference/pdo/pdostatement/setfetchmode.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-setFetchMode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->setFetchMode()</refname> <refpurpose> Set the default fetch mode for this statement </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>mode</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>PDO::FETCH_COLUMN</parameter></methodparam> <methodparam><type>int</type><parameter>colno</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>PDO::FETCH_CLASS</parameter></methodparam> <methodparam><type>string</type><parameter>classname</parameter></methodparam> <methodparam><type>array</type><parameter>ctorargs</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>PDO::FETCH_INTO</parameter></methodparam> <methodparam><type>object</type><parameter>object</parameter></methodparam> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>mode</parameter></term> <listitem> <para> The fetch mode must be one of the <literal>PDO::FETCH_*</literal> constants. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns <literal>1</literal> on success or &false; on failure. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Setting the fetch mode</title> <para> The following example demonstrates how <xref linkend="function.PDOStatement-setFetchMode" /> changes the default fetch mode for a PDOStatement object. </para> <programlisting role="php"> <![CDATA[ <?php $sql = 'SELECT name, colour, calories FROM fruit'; try { $stmt = $dbh->query($sql); $result = $stmt->setFetchMode(PDO::FETCH_NUM); while ($row = $stmt->fetch()) { print $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; } } catch (PDOException $e) { print $e->getMessage(); } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple red 150 banana yellow 250 orange orange 300 kiwi brown 75 lemon yellow 25 pear green 150 watermelon pink 90 ]]> </screen> </example> </para> </refsect1> <!-- Use when adding See Also links <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><function></function></member> <member>Or <link linkend="somethingelse">something else</link></member> </simplelist> </para> </refsect1> --> </refentry> <!-- 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 -->
http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/begintransaction.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/begintransaction.xml +++ phpdoc/en/reference/pdo/pdo/begintransaction.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-beginTransaction" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->beginTransaction()</refname> <refpurpose> Initiates a transaction </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>beginTransaction</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO object instance are not committed until you end the transaction by calling <xref linkend="function.PDO-commit" />. Calling <xref linkend="function.PDO-rollBack" /> will roll back all changes to the database and return the connection to autocommit mode. </para> <para> Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Roll back a transaction</title> <para> The following example begins a transaction and issues two statements that modify the database before rolling back the changes. On MySQL, however, the DROP TABLE statement automatically commits the transaction so that none of the changes in the transaction are rolled back. </para> <programlisting role='php'> <![CDATA[ <?php /* Begin a transaction, turning off autocommit */ $dbh->beginTransaction(); /* Change the database schema and data */ $sth = $dbh->exec("DROP TABLE fruit"); $sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'"); /* Recognize mistake and roll back changes */ $dbh->rollBack(); /* Database connection is now back in autocommit mode */ ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-commit" /></member> <member><xref linkend="function.PDO-rollBack" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/commit.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/commit.xml +++ phpdoc/en/reference/pdo/pdo/commit.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-commit" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->commit()</refname> <refpurpose> Commits a transaction </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>commit</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Commits a transaction, returning the database connection to autocommit mode until the next call to <xref linkend="function.PDO-beginTransaction" /> starts a new transaction. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Commit a transaction</title> <programlisting role='php'> <![CDATA[ <?php /* Begin a transaction, turning off autocommit */ $dbh->beginTransaction(); /* Change the database schema */ $sth = $dbh->exec("DROP TABLE fruit"); /* Commit the changes */ $dbh->commit(); /* Database connection is now back in autocommit mode */ ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-beginTransaction" /></member> <member><xref linkend="function.PDO-rollBack" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/construct.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/construct.xml +++ phpdoc/en/reference/pdo/pdo/construct.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-construct" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->__construct()</refname> <refpurpose> Creates a PDO instance representing a connection to a database </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDO</type><methodname>__construct</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> <methodparam choice="opt"><type>array</type><parameter>driver_options</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Creates a PDO instance to represent a connection to the requested database. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry><term>dsn</term> <listitem> <para> The Data Source Name, or DSN, contains the information required to connect to the database. </para> <para> In general, a DSN consists of the PDO driver name, followed by a colon, followed by the PDO driver-specific connection syntax. Further information is available from the <link linkend="pdo.drivers">PDO driver-specific documentation</link>. </para> <para> The <parameter>dsn</parameter> parameter supports three different methods of specifying the arguments required to create a database connection: </para> <para> <variablelist> <varlistentry><term>Driver invocation</term> <listitem> <para> <parameter>dsn</parameter> contains the full DSN. </para> </listitem> </varlistentry> <varlistentry><term>URI invocation</term> <listitem> <para> <parameter>dsn</parameter> consists of <userinput>uri:</userinput> followed by a URI that defines the location of a file containing the DSN string. The URI can specify a local file or a remote URL. </para> <para><userinput>uri:file:///path/to/dsnfile</userinput></para> </listitem> </varlistentry> <varlistentry><term>Aliasing</term> <listitem> <para> <parameter>dsn</parameter> consists of a name <parameter>name</parameter> that maps to <code>pdo.dsn.<parameter>name</parameter></code> in &php.ini; defining the DSN string. </para> <note> <para> The alias must be defined in &php.ini;, and not &htaccess; or &httpd.conf; </para> </note> </listitem> </varlistentry> </variablelist> </para> </listitem> </varlistentry> <varlistentry><term>username</term> <listitem> <para> The user name for the DSN string. This parameter is optional for some PDO drivers. </para> </listitem> </varlistentry> <varlistentry><term>password</term> <listitem> <para> The password for the DSN string. This parameter is optional for some PDO drivers. </para> </listitem> </varlistentry> <varlistentry><term>driver_options</term> <listitem> <para> A key=>value array of driver-specific connection options. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns a PDO object on success. </para> </refsect1> <refsect1 role="errors"> &reftitle.errors; <para> <xref linkend="function.PDO-construct" /> throws a PDOException if the attempt to connect to the requested database fails. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Create a PDO instance via driver invocation</title> <programlisting role="php"> <![CDATA[ <?php /* Connect to an ODBC database using driver invocation */ $dsn = 'mysql:dbname=testdb;host=127.0.0.1'; $user = 'dbuser'; $password = 'dbpass'; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } ?> ]]> </programlisting> </example> <example><title>Create a PDO instance via URI invocation</title> <para> The following example assumes that the file <filename>/usr/local/dbconnect</filename> exists with file permissions that enable PHP to read the file. The file contains the PDO DSN to connect to a DB2 database through the PDO_ODBC driver: </para> <screen> <![CDATA[ odbc:DSN=SAMPLE;UID=john;PWD=mypass ]]> </screen> <para> The PHP script can then create a database connection by simply passing the <literal>uri:</literal> parameter and pointing to the file URI: </para> <programlisting role="php"> <![CDATA[ <?php /* Connect to an ODBC database using driver invocation */ $dsn = 'uri:file:///usr/local/dbconnect'; $user = ''; $password = ''; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } ?> ]]> </programlisting> </example> <example><title>Create a PDO instance using an alias</title> <para> The following example assumes that &php.ini; contains the following entry to enable a connection to a MySQL database using only the alias <literal>mydb</literal>: <programlisting role="ini"> [PDO] pdo.dsn.mydb="mysql:dbname=testdb;host=localhost" </programlisting> </para> <programlisting role="php"> <![CDATA[ <?php /* Connect to an ODBC database using an alias */ $dsn = 'mydb'; $user = ''; $password = ''; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } ?> ]]> </programlisting> </example> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/errorcode.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/errorcode.xml +++ phpdoc/en/reference/pdo/pdo/errorcode.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-errorCode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->errorCode()</refname> <refpurpose> Fetch the SQLSTATE associated with the last operation on the database handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>string</type><methodname>errorCode</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns a SQLSTATE, a five-character alphanumeric identifier defined in the ANSI SQL-92 standard. Briefly, an SQLSTATE consists of a two-character class value followed by a three-character subclass value. A class value of 01 indicates a warning and is accompanied by a return code of SQL_SUCCESS_WITH_INFO. Class values other than '01', except for the class 'IM', indicate an error. The class 'IM' is specific to warnings and errors that derive from the implementation of PDO (or perhaps ODBC, if you're using the ODBC driver) itself. The subclass value '000' in any class indicates that there is no subclass for that SQLSTATE. </para> <para> <xref linkend="function.PDO-errorCode" /> only retrieves error codes for operations performed directly on the database handle. If you create a PDOStatement object through <xref linkend="function.PDO-prepare" /> or <xref linkend="function.PDO-query" /> and invoke an error on the statement handle, <xref linkend="function.PDO-errorCode" /> will not reflect that error. You must call <xref linkend="function.PDOStatement-errorCode" /> to return the error code for an operation performed on a particular statement handle. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Retrieving a SQLSTATE code</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- the BONES table does not exist */ $dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')"); echo "\nPDO::errorCode(): "; print $dbh->errorCode(); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDO::errorCode(): 42S02 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorInfo" /></member> <member><xref linkend="function.PDOStatement-errorCode" /></member> <member><xref linkend="function.PDOStatement-errorInfo" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/errorinfo.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/errorinfo.xml +++ phpdoc/en/reference/pdo/pdo/errorinfo.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-errorInfo" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->errorInfo()</refname> <refpurpose> Fetch extended error information associated with the last operation on the database handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>array</type><methodname>errorInfo</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-errorInfo" /> returns an array of error information about the last operation performed by this database handle. The array consists of the following fields: <informaltable> <tgroup cols='2'> <thead> <row> <entry>Element</entry> <entry>Information</entry> </row> </thead> <tbody> <row> <entry>0</entry> <entry>SQLSTATE error code (a five-character alphanumeric identifier defined in the ANSI SQL standard).</entry> </row> <row> <entry>1</entry> <entry>Driver-specific error code.</entry> </row> <row> <entry>2</entry> <entry>Driver-specific error message.</entry> </row> </tbody> </tgroup> </informaltable> </para> <para> <xref linkend="function.PDO-errorInfo" /> only retrieves error information for operations performed directly on the database handle. If you create a PDOStatement object through <xref linkend="function.PDO-prepare" /> or <xref linkend="function.PDO-query" /> and invoke an error on the statement handle, <xref linkend="function.PDO-errorInfo" /> will not reflect the error from the statement handle. You must call <xref linkend="function.PDOStatement-errorInfo" /> to return the error information for an operation performed on a particular statement handle. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Displaying errorInfo() fields for a PDO_ODBC connection to a DB2 database</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- bogus SQL syntax */ $stmt = $dbh->prepare('bogus sql'); if (!$stmt) { echo "\nPDO::errorInfo():\n"; print_r($dbh->errorInfo()); } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDO::errorInfo(): Array ( [0] => HY000 [1] => 1 [2] => near "bogus": syntax error ) ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorCode" /></member> <member><xref linkend="function.PDOStatement-errorCode" /></member> <member><xref linkend="function.PDOStatement-errorInfo" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/exec.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/exec.xml +++ phpdoc/en/reference/pdo/pdo/exec.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-exec" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->exec()</refname> <refpurpose> Execute an SQL statement and return the number of affected rows </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>int</type><methodname>exec</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDO-exec" /> executes an SQL statement in a single function call, returning the number of rows affected by the statement. </para> <para> <xref linkend="function.PDO-exec" /> does not return results from a SELECT statement. For a SELECT statement that you only need to issue once during your program, consider issuing <xref linkend="function.PDO-query" />. For a statement that you need to issue multiple times, prepare a PDOStatement object with <xref linkend="function.PDO-prepare" /> and issue the statement with <xref linkend="function.PDOStatement-execute" />. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>statement</parameter></term> <listitem> <para> The SQL statement to prepare and execute. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-exec" /> returns the number of rows that were modified or deleted by the SQL statement you issued. If no rows were affected, <xref linkend="function.PDO-exec" /> returns <literal>0</literal>. </para> &return.falseproblem; <para> The following example incorrectly relies on the return value of <xref linkend="function.PDO-exec" />, wherein a statement that affected 0 rows results in a call to <function>die</function>: <programlisting role="php"> <![CDATA[ <?php $db->exec() or die($db->errorInfo()); ?> ]]> </programlisting> </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Issuing a DELETE statement</title> <para> Count the number of rows deleted by a DELETE statement with no WHERE clause. </para> <programlisting role="php"> <![CDATA[ <?php $dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); /* Delete all rows from the FRUIT table */ $count = $dbh->exec("DELETE FROM fruit WHERE colour = 'red'"); /* Return number of rows that were deleted */ print("Deleted $count rows.\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Deleted 1 rows. ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/getattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/getattribute.xml +++ phpdoc/en/reference/pdo/pdo/getattribute.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-getAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->getAttribute()</refname> <refpurpose> Retrieve a database connection attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>getAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> This function returns the value of a database connection attribute. To retrieve PDOStatement attributes, refer to <xref linkend="function.PDOStatement-getAttribute" />. </para> <para> Note that some database/driver combinations may not support all of the database connection attributes. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>attribute</parameter></term> <listitem> <para> One of the <literal>PDO::ATTR_*</literal> constants. The constants that apply to database connections are as follows: <simplelist> <member><literal>PDO::ATTR_AUTOCOMMIT</literal></member> <member><literal>PDO::ATTR_CASE</literal></member> <member><literal>PDO::ATTR_CLIENT_VERSION</literal></member> <member><literal>PDO::ATTR_CONNECTION_STATUS</literal></member> <member><literal>PDO::ATTR_DRIVER_NAME</literal></member> <member><literal>PDO::ATTR_ERRMODE</literal></member> <member><literal>PDO::ATTR_ORACLE_NULLS</literal></member> <member><literal>PDO::ATTR_PERSISTENT</literal></member> <member><literal>PDO::ATTR_PREFETCH</literal></member> <member><literal>PDO::ATTR_SERVER_INFO</literal></member> <member><literal>PDO::ATTR_SERVER_VERSION</literal></member> <member><literal>PDO::ATTR_TIMEOUT</literal></member> </simplelist> </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> A successful call returns the value of the requested PDO attribute. An unsuccessful call returns <literal>null</literal>. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Retrieving database connection attributes</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); $attributes = array( "AUTOCOMMIT", "ERRMODE", "CASE", "CLIENT_VERSION", "CONNECTION_STATUS", "ORACLE_NULLS", "PERSISTENT", "PREFETCH", "SERVER_INFO", "SERVER_VERSION", "TIMEOUT" ); foreach ($attributes as $val) { echo "PDO::ATTR_$val: "; echo $conn->getAttribute(constant("PDO::ATTR_$val")) . "\n"; } ?> ]]> </programlisting> <!-- &example.outputs; <screen> <![CDATA[ Use the PEAR Coding Standards ]]> </screen> --> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-setAttribute" /></member> <member><xref linkend="function.PDOStatement-getAttribute" /></member> <member><xref linkend="function.PDOStatement-setAttribute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/getavailabledrivers.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/getavailabledrivers.xml +++ phpdoc/en/reference/pdo/pdo/getavailabledrivers.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-getAvailableDrivers" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->getAvailableDrivers()</refname> <refpurpose> Return an array of available PDO drivers </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>array</type><methodname>getAvailableDrivers</methodname> <void/> </methodsynopsis> </classsynopsis> <para> This function returns all currently available PDO drivers which can be used in <parameter>DSN</parameter> parameter of <xref linkend="function.PDO-construct" />. This is a static method. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-getAvailableDrivers" /> returns an array of PDO driver names. If no drivers are available, it returns an empty array. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>A <xref linkend="function.PDO-getAvailableDrivers" /> example</title> <programlisting role="php"> <![CDATA[ <?php print_r(PDO::getAvailableDrivers()); ?> ]]> </programlisting> &example.outputs.similar; <screen> <![CDATA[ Array ( [0] => mysql [1] => sqlite ) ]]> </screen> </example> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/lastinsertid.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/lastinsertid.xml +++ phpdoc/en/reference/pdo/pdo/lastinsertid.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-lastInsertId" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->lastInsertId()</refname> <refpurpose> Returns the ID of the last inserted row or sequence value </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>string</type><methodname>lastInsertId</methodname> <methodparam choice="opt"><type>string</type><parameter>name</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Returns the ID of the last inserted row, or the last value from a sequence object, depending on the underlying driver. For example, <function>PDO_PGSQL</function> requires you to specify the name of a sequence object for the <parameter>name</parameter> parameter. </para> <note> <para> This method may not return a meaningful or consistent result across different PDO drivers, because the underlying database may not even support the notion of auto-increment fields or sequences. </para> </note> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>name</parameter></term> <listitem> <para> Name of the sequence object from which the ID should be returned. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> If a sequence name was not specified for the <parameter>name</parameter> parameter, <xref linkend="function.PDO-lastInsertId" /> returns a string representing the row ID of the last row that was inserted into the database. </para> <para> If a sequence name was specified for the <parameter>name</parameter> parameter, <xref linkend="function.PDO-lastInsertId" /> returns a string representing the last value retrieved from the specified sequence object. </para> <para> If the PDO driver does not support this capability, <xref linkend="function.PDO-lastInsertId" /> triggers an <literal>IM001</literal> SQLSTATE. </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/prepare.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/prepare.xml +++ phpdoc/en/reference/pdo/pdo/prepare.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-prepare" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->prepare()</refname> <refpurpose> Prepares a statement for execution and returns a statement object </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>prepare</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>driver_options</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Prepares an SQL statement to be executed by the <xref linkend="function.PDOStatement-execute" /> method. The SQL statement can contain zero or more named (:name) or question mark (?) parameter markers for which real values will be substituted when the statement is executed. You cannot use both named and question mark parameter markers within the same SQL statement; pick one or the other parameter style. </para> <para> You must include a unique parameter marker for each value you wish to pass in to the statement when you call <xref linkend="function.PDOStatement-execute" />. You cannot use a named parameter marker of the same name twice in a prepared statement. You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement. </para> <para> Calling <xref linkend="function.PDO-prepare" /> and <xref linkend="function.PDOStatement-execute" /> for statements that will be issued multiple times with different parameter values optimizes the performance of your application by allowing the driver to negotiate client and/or server side caching of the query plan and meta information, and helps to prevent SQL injection attacks by eliminating the need to manually quote the parameters. </para> <para> PDO will emulate prepared statements/bound parameters for drivers that do not natively support them, and can also rewrite named or question mark style parameter markers to something more appropriate, if the driver supports one style but not the other. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>statement</parameter></term> <listitem> <para> This must be a valid SQL statement for the target database server. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>driver_options</parameter></term> <listitem> <para> This array holds one or more key=>value pairs to set attribute values for the PDOStatement object that this method returns. You would most commonly use this to set the <literal>PDO::ATTR_CURSOR</literal> value to <literal>PDO::CURSOR_SCROLL</literal> to request a scrollable cursor. Some drivers have driver specific options that may be set at prepare-time. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> If the database server successfully prepares the statement, <xref linkend="function.PDO-prepare" /> returns a PDOStatement object. If the database server cannot successfully prepare the statement, <xref linkend="function.PDO-prepare" /> returns &false;. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Prepare an SQL statement with named parameters</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by passing an array of values */ $sql = 'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'; $sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $sth->execute(array(':calories' => 150, ':colour' => 'red')); $red = $sth->fetchAll(); $sth->execute(array('calories' => 175, 'colour' => 'yellow')); $yellow = $sth->fetchAll(); ?> ]]> </programlisting> </example> <example> <title>Prepare an SQL statement with question mark parameters</title> <programlisting role='php'> <![CDATA[ <?php /* 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')); $red = $sth->fetchAll(); $sth->execute(array(175, 'yellow')); $yellow = $sth->fetchAll(); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-exec" /></member> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/query.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/query.xml +++ phpdoc/en/reference/pdo/pdo/query.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-query" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->query()</refname> <refpurpose> Executes an SQL statement, returning a result set as a PDOStatement object </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam><type>int</type><parameter>PDO::FETCH_COLUMN</parameter></methodparam> <methodparam><type>int</type><parameter>colno</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam><type>int</type><parameter>PDO::FETCH_CLASS</parameter></methodparam> <methodparam><type>string</type><parameter>classname</parameter></methodparam> <methodparam><type>array</type><parameter>ctorargs</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>PDOStatement</type><methodname>query</methodname> <methodparam><type>string</type><parameter>statement</parameter></methodparam> <methodparam><type>int</type><parameter>PDO::FETCH_INTO</parameter></methodparam> <methodparam><type>object</type><parameter>object</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDO-query" /> executes an SQL statement in a single function call, returning the result set (if any) returned by the statement as a PDOStatement object. </para> <para> For a query that you need to issue multiple times, you will realize better performance if you prepare a PDOStatement object using <xref linkend="function.PDO-prepare" /> and issue the statement with multiple calls to <xref linkend="function.PDOStatement-execute" />. </para> <para> If you do not fetch all of the data in a result set before issuing your next call to <xref linkend="function.PDO-query" />, your call may fail. Call <xref linkend="function.PDOStatement-closeCursor" /> to release the database resources associated with the PDOStatement object before issuing your next call to <xref linkend="function.PDO-query" />. </para> <note> <para> Although this function is only documented as having a single parameter, you may pass additional arguments to this function. They will be treated as though you called <xref linkend="function.PDOStatement-setFetchMode" /> on the resultant statement object. </para> </note> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>statement</parameter></term> <listitem> <para> The SQL statement to prepare and execute. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDO-query" /> returns a PDOStatement object. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Demonstrate PDO::query</title> <para> A nice feature of <xref linkend="function.PDO-query" /> is that it enables you to iterate over the rowset returned by a successfully executed SELECT statement. </para> <programlisting role="php"> <![CDATA[ <?php function getFruit($conn) { $sql = 'SELECT name, colour, calories FROM fruit ORDER BY name'; foreach ($conn->query($sql) as $row) { print $row['NAME'] . "\t"; print $row['COLOUR'] . "\t"; print $row['CALORIES'] . "\n"; } } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple red 150 banana yellow 250 kiwi brown 75 lemon yellow 25 orange orange 300 pear green 150 watermelon pink 90 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-exec" /></member> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/quote.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/quote.xml +++ phpdoc/en/reference/pdo/pdo/quote.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-quote" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->quote()</refname> <refpurpose> Quotes a string for use in a query. </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>string</type><methodname>quote</methodname> <methodparam><type>string</type><parameter>string</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>parameter_type</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDO-quote" /> places quotes around the input string (if required) and escapes special characters within the input string, using a quoting style appropriate to the underlying driver. </para> <para> If you are using this function to build SQL statements, you are <emphasis>strongly</emphasis> recommended to use <xref linkend="function.PDO-prepare" /> to prepare SQL statements with bound parameters instead of using <xref linkend="function.PDO-quote" /> to interpolate user input into a SQL statement. Prepared statements with bound parameters are not only more portable, more convenient, immune to SQL injection, but are often much faster to execute than interpolated queries, as both the server and client side can cache a compiled form of the query. </para> <para> Not all PDO drivers implement this method (notably PDO_ODBC). Consider using prepared statements instead. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>string</parameter></term> <listitem> <para> The string to be quoted. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>parameter_type</parameter></term> <listitem> <para> Provides a data type hint for drivers that have alternate quoting styles. The default value is PDO::PARAM_STR. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns a quoted string that is theoretically safe to pass into an SQL statement. Returns &false; if the driver does not support quoting in this way. </para> </refsect1> <!-- Use when ERRORS exist <refsect1 role="errors"> &reftitle.errors; <para> When does this function throw E_* level errors, or exceptions? </para> </refsect1> --> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Quoting a normal string</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('sqlite:/home/lynn/music.sql3'); /* Simple string */ $string = 'Nice'; print "Unquoted string: $string\n"; print "Quoted string: " . $conn->quote($string) . "\n"; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Unquoted string: Nice Quoted string: 'Nice' ]]> </screen> </example> <example> <title>Quoting a dangerous string</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('sqlite:/home/lynn/music.sql3'); /* Dangerous string */ $string = 'Naughty \' string'; print "Unquoted string: $string\n"; print "Quoted string:" . $conn->quote($string) . "\n"; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Unquoted string: Naughty ' string Quoted string: 'Naughty '' string' ]]> </screen> </example> <example> <title>Quoting a complex string</title> <programlisting role="php"> <![CDATA[ <?php $conn = new PDO('sqlite:/home/lynn/music.sql3'); /* Complex string */ $string = "Co'mpl''ex \"st'\"ring"; print "Unquoted string: $string\n"; print "Quoted string: " . $conn->quote($string) . "\n"; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Unquoted string: Co'mpl''ex "st'"ring Quoted string: 'Co''mpl''''ex "st''"ring' ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/rollback.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/rollback.xml +++ phpdoc/en/reference/pdo/pdo/rollback.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-rollBack" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->rollBack()</refname> <refpurpose> Rolls back a transaction </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>rollBack</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Rolls back the current transaction, as initiated by <xref linkend="function.PDO-beginTransaction" />. It is an error to call this method if no transaction is active. </para> <para> If the database was set to autocommit mode, this function will restore autocommit mode after it has rolled back the transaction. </para> <para> Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Roll back a transaction</title> <para> The following example begins a transaction and issues two statements that modify the database before rolling back the changes. On MySQL, however, the DROP TABLE statement automatically commits the transaction so that none of the changes in the transaction are rolled back. </para> <programlisting role='php'> <![CDATA[ <?php /* Begin a transaction, turning off autocommit */ $dbh->beginTransaction(); /* Change the database schema and data */ $sth = $dbh->exec("DROP TABLE fruit"); $sth = $dbh->exec("UPDATE dessert SET name = 'hamburger'"); /* Recognize mistake and roll back changes */ $dbh->rollBack(); /* Database connection is now back in autocommit mode */ ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-beginTransaction" /></member> <member><xref linkend="function.PDO-commit" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdo/setattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdo/setattribute.xml +++ phpdoc/en/reference/pdo/pdo/setattribute.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDO-setAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDO->setAttribute()</refname> <refpurpose> Set an attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDO</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> <methodparam><type>mixed</type><parameter>value</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Sets an attribute on the database handle. Some of the available generic attributes are listed below; some drivers may make use of additional driver specific attributes. <itemizedlist> <listitem><para> <literal>PDO::ATTR_CASE</literal>: Force column names to a specific case. <itemizedlist> <listitem><para> <literal>PDO::CASE_LOWER</literal>: Force column names to lower case. </para></listitem> <listitem><para> <literal>PDO::CASE_NATURAL</literal>: Leave column names as returned by the database driver. </para></listitem> <listitem><para> <literal>PDO::CASE_UPPER</literal>: Force column names to upper case. </para></listitem> </itemizedlist> </para></listitem> <listitem><para><literal>PDO::ATTR_ERRMODE</literal>: Error reporting. <itemizedlist> <listitem><para><literal>PDO::ERRMODE_SILENT</literal>: Just set error codes.</para></listitem> <listitem><para><literal>PDO::ERRMODE_WARNING</literal>: Raise <link linkend="errorfunc.constants.errorlevels.e-warning">E_WARNING</link>.</para></listitem> <listitem><para><literal>PDO::ERRMODE_EXCEPTION</literal>: Throw <link linkend="language.exceptions">exceptions</link>.</para></listitem> </itemizedlist> </para></listitem> <listitem><para><literal>PDO::ATTR_ORACLE_NULLS</literal> (available with all drivers, not just Oracle): Conversion of NULL and empty strings. <itemizedlist> <listitem><para><literal>PDO::NULL_NATURAL</literal>: No conversion.</para></listitem> <listitem><para><literal>PDO::NULL_EMPTY_STRING</literal>: Empty string is converted to &null;.</para></listitem> <listitem><para><literal>PDO::NULL_TO_STRING</literal>: NULL is converted to an empty string.</para></listitem> </itemizedlist> </para></listitem> <listitem><para><literal>PDO::ATTR_STRINGIFY_FETCHES</literal>: Convert numeric values to strings when fetching. Requires <type>bool</type>. </para></listitem> <listitem><para><literal>PDO::ATTR_STATEMENT_CLASS</literal>: Set user-supplied statement class derived from PDOStatement. Cannot be used with persistent PDO instances. Requires <literal>array(string classname, array(mixed constructor_args))</literal>. </para></listitem> <listitem><para><literal>PDO::ATTR_AUTOCOMMIT</literal> (available in OCI, Firebird and MySQL): Whether to autocommit every single statement. </para></listitem> <listitem><para><literal>PDO::MYSQL_ATTR_USE_BUFFERED_QUERY</literal> (available in MySQL): Use buffered queries. </para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/bindcolumn.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/bindcolumn.xml +++ phpdoc/en/reference/pdo/pdostatement/bindcolumn.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-bindColumn" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->bindColumn()</refname> <refpurpose> Bind a column to a PHP variable </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>bindColumn</methodname> <methodparam><type>mixed</type><parameter>column</parameter></methodparam> <methodparam><type>mixed</type><parameter role="reference">param</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>type</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDOStatement-bindColumn" /> arranges to have a particular variable bound to a given column in the result-set from a query. Each call to <xref linkend="function.PDOStatement-fetch" /> or <xref linkend="function.PDOStatement-fetchAll" /> will update all the variables that are bound to columns. </para> <note> <para> Since information about the columns is not always available to PDO until the statement is executed, portable applications should call this function <emphasis>after</emphasis> <xref linkend="function.PDOStatement-execute" />. </para> </note> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>column</parameter></term> <listitem> <para> Number of the column (1-indexed) or name of the column in the result set. If using the column name, be aware that the name should match the case of the column, as returned by the driver. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>param</parameter></term> <listitem> <para> Name of the PHP variable to which the column will be bound. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>type</parameter></term> <listitem> <para> Data type of the parameter, specified by the PDO::PARAM_* constants. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Binding result set output to PHP variables</title> <para> Binding columns in the result set to PHP variables is an effective way to make the data contained in each row immediately available to your application. The following example demonstrates how PDO allows you to bind and retrieve columns with a variety of options and with intelligent defaults. </para> <programlisting role="php"> <![CDATA[ <?php function readData($dbh) { $sql = 'SELECT name, colour, calories FROM fruit'; try { $stmt = $dbh->prepare($sql); $stmt->execute(); /* Bind by column number */ $stmt->bindColumn(1, $name); $stmt->bindColumn(2, $colour); /* Bind by column name */ $stmt->bindColumn('calories', $cals); while ($row = $stmt->fetch(PDO::FETCH_BOUND)) { $data = $name . "\t" . $colour . "\t" . $cals . "\n"; print $data; } } catch (PDOException $e) { print $e->getMessage(); } } readData($dbh); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple red 150 banana yellow 175 kiwi green 75 orange orange 150 mango red 200 strawberry red 25 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/bindparam.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/bindparam.xml +++ phpdoc/en/reference/pdo/pdostatement/bindparam.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-bindParam" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->bindParam()</refname> <refpurpose> Binds a parameter to the specified variable name </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>bindParam</methodname> <methodparam><type>mixed</type><parameter>parameter</parameter></methodparam> <methodparam><type>mixed</type><parameter role="reference">variable</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>data_type</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam> <methodparam choice="opt"><type>mixed</type><parameter>driver_options</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Binds a PHP variable to a corresponding named or question mark placeholder in the SQL statement that was use to prepare the statement. Unlike <xref linkend="function.PDOStatement-bindValue" />, the variable is bound as a reference and will only be evaluated at the time that <xref linkend="function.PDOStatement-execute" /> is called. </para> <para> Most parameters are input parameters, that is, parameters that are used in a read-only fashion to build up the query. Some drivers support the invocation of stored procedures that return data as output parameters, and some also as input/output parameters that both send in data and are updated to receive it. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>parameter</parameter></term> <listitem> <para> Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form <varname>:name</varname>. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>variable</parameter></term> <listitem> <para> Name of the PHP variable to bind to the SQL statement parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>data_type</parameter></term> <listitem> <para> Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PHP native type. To return an INOUT parameter from a stored procedure, use the bitwise OR operator to set the PDO::PARAM_INPUT_OUTPUT bits for the <parameter>data_type</parameter> parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>length</parameter></term> <listitem> <para> Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>driver_options</parameter></term> <listitem> <para> </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example><title>Execute a prepared statement with named placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute(); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with question mark placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* 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>Pass a NULL value into a prepared statement</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); /* Find fruit with a NULL value in the colour column */ $sth->bindParam(':colour', $colour, PDO::PARAM_NULL); $sth->execute(); ?> ]]> </programlisting> </example> --> <example><title>Call a stored procedure with an INOUT parameter</title> <programlisting role='php'> <![CDATA[ <?php /* Call a stored procedure with an INOUT parameter */ $colour = 'red'; $sth = $dbh->prepare('CALL puree_fruit(?)'); $sth->bindParam(1, $colour, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, 12); $sth->execute(); print("After pureeing fruit, the colour is: $colour"); ?> ]]> </programlisting> </example> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-bindValue" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/bindvalue.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/bindvalue.xml +++ phpdoc/en/reference/pdo/pdostatement/bindvalue.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-bindValue" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->bindValue()</refname> <refpurpose> Binds a value to a parameter </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>bindValue</methodname> <methodparam><type>mixed</type><parameter>parameter</parameter></methodparam> <methodparam><type>mixed</type><parameter>value</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>data_type</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Binds a value to a corresponding named or question mark placeholder in the SQL statement that was use to prepare the statement. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>parameter</parameter></term> <listitem> <para> Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form <varname>:name</varname>. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>value</parameter></term> <listitem> <para> The value to bind to the parameter. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>data_type</parameter></term> <listitem> <para> Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PHP native type. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example><title>Execute a prepared statement with named placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindValue(':calories', $calories, PDO::PARAM_INT); $sth->bindValue(':colour', $colour, PDO::PARAM_STR); $sth->execute(); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with question mark placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* 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->bindValue(1, $calories, PDO::PARAM_INT); $sth->bindValue(2, $colour, PDO::PARAM_STR); $sth->execute(); ?> ]]> </programlisting> </example> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-bindParam" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/closecursor.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/closecursor.xml +++ phpdoc/en/reference/pdo/pdostatement/closecursor.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-closeCursor" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->closeCursor()</refname> <refpurpose> Closes the cursor, enabling the statement to be executed again. </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>closeCursor</methodname> <void/> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDOStatement-closeCursor" /> frees up the connection to the server so that other SQL statements may be issued, but leaves the statement in a state that enables it to be executed again. </para> <para> This method is useful for database drivers that do not support executing a PDOStatement object when a previously executed PDOStatement object still has unfetched rows. If your database driver suffers from this limitation, the problem may manifest itself in an out-of-sequence error. </para> <para> <xref linkend="function.PDOStatement-closeCursor" /> is implemented either as an optional driver specific method (allowing for maximum efficiency), or as the generic PDO fallback if no driver specific function is installed. The PDO generic fallback is semantically the same as writing the following code in your PHP script: <programlisting role="php"> <![CDATA[ <?php do { while ($stmt->fetch()) ; if (!$stmt->nextRowset()) break; } while (true); ?> ]]> </programlisting> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>A <xref linkend="function.PDOStatement-closeCursor" /> example</title> <para> In the following example, the <varname>$stmt</varname> PDOStatement object returns multiple rows but the application fetches only the first row, leaving the PDOStatement object in a state of having unfetched rows. To ensure that the application will work with all database drivers, the author inserts a call to <xref linkend="function.PDOStatement-closeCursor" /> on <varname>$stmt</varname> before executing the <varname>$otherStmt</varname> PDOStatement object. </para> <programlisting role="php"> <![CDATA[ <?php /* Create a PDOStatement object */ $stmt = $dbh->prepare('SELECT foo FROM bar'); /* Create a second PDOStatement object */ $otherStmt = $dbh->prepare('SELECT foobaz FROM foobar'); /* Execute the first statement */ $stmt->execute(); /* Fetch only the first row from the results */ $stmt->fetch(); /* The following call to closeCursor() may be required by some drivers */ $stmt->closeCursor(); /* Now we can execute the second statement */ $otherStmt->execute(); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-execute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/columncount.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/columncount.xml +++ phpdoc/en/reference/pdo/pdostatement/columncount.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-columnCount" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->columnCount()</refname> <refpurpose> Returns the number of columns in the result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>int</type><methodname>columnCount</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Use <xref linkend="function.PDOStatement-columnCount" /> to return the number of columns in the result set represented by the PDOStatement object. </para> <para> If the PDOStatement object was returned from <xref linkend="function.PDO-query" />, the column count is immediately available. </para> <para> If the PDOStatement object was returned from <xref linkend="function.PDO-prepare" />, an accurate column count will not be available until you invoke <xref linkend="function.PDOStatement-execute" />. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns the number of columns in the result set represented by the PDOStatement object. If there is no result set, <xref linkend="function.PDOStatement-columnCount" /> returns <literal>0</literal>. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Counting columns</title> <para> This example demonstrates how <xref linkend="function.PDOStatement-columnCount" /> operates with and without a result set. </para> <programlisting role="php"> <![CDATA[ <?php $dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); $sth = $dbh->prepare("SELECT name, colour FROM fruit"); /* Count the number of columns in the (non-existent) result set */ $colcount = $sth->columnCount(); print("Before execute(), result set has $colcount columns (should be 0)\n"); $sth->execute(); /* Count the number of columns in the result set */ $colcount = $sth->columnCount(); print("After execute(), result set has $colcount columns (should be 2)\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Before execute(), result set has 0 columns (should be 0) After execute(), result set has 2 columns (should be 2) ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-rowCount" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/errorcode.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/errorcode.xml +++ phpdoc/en/reference/pdo/pdostatement/errorcode.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-errorCode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->errorCode()</refname> <refpurpose> Fetch the SQLSTATE associated with the last operation on the statement handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>string</type><methodname>errorCode</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Identical to <xref linkend="function.PDO-errorCode" />, except that <xref linkend="function.PDOStatement-errorCode" /> only retrieves error codes for operations performed with PDOStatement objects. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Retrieving a SQLSTATE code</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- the BONES table does not exist */ $err = $dbh->prepare('SELECT skull FROM bones'); $err->execute(); echo "\nPDOStatement::errorCode(): "; print $err->errorCode(); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDOStatement::errorCode(): 42S02 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorCode" /></member> <member><xref linkend="function.PDO-errorInfo" /></member> <member><xref linkend="function.PDOStatement-errorInfo" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/errorinfo.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/errorinfo.xml +++ phpdoc/en/reference/pdo/pdostatement/errorinfo.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-errorInfo" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->errorInfo()</refname> <refpurpose> Fetch extended error information associated with the last operation on the statement handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>array</type><methodname>errorInfo</methodname> <void/> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDOStatement-errorInfo" /> returns an array of error information about the last operation performed by this statement handle. The array consists of the following fields: <informaltable> <tgroup cols='2'> <thead> <row> <entry>Element</entry> <entry>Information</entry> </row> </thead> <tbody> <row> <entry>0</entry> <entry>SQLSTATE error code (a five-character alphanumeric identifier defined in the ANSI SQL standard).</entry> </row> <row> <entry>1</entry> <entry>Driver-specific error code.</entry> </row> <row> <entry>2</entry> <entry>Driver-specific error message.</entry> </row> </tbody> </tgroup> </informaltable> </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Displaying errorInfo() fields for a PDO_ODBC connection to a DB2 database</title> <programlisting role="php"> <![CDATA[ <?php /* Provoke an error -- the BONES table does not exist */ $sth = $dbh->prepare('SELECT skull FROM bones'); $sth->execute(); echo "\nPDOStatement::errorInfo():\n"; $arr = $sth->errorInfo(); print_r($arr); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDOStatement::errorInfo(): Array ( [0] => 42S02 [1] => -204 [2] => [IBM][CLI Driver][DB2/LINUX] SQL0204N "DANIELS.BONES" is an undefined name. SQLSTATE=42704 ) ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-errorCode" /></member> <member><xref linkend="function.PDO-errorInfo" /></member> <member><xref linkend="function.PDOStatement-errorCode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/execute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/execute.xml +++ phpdoc/en/reference/pdo/pdostatement/execute.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-execute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->execute()</refname> <refpurpose> Executes a prepared statement </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>execute</methodname> <methodparam choice="opt"><type>array</type><parameter>input_parameters</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Execute the prepared statement. If the prepared statement included parameter markers, you must either: <itemizedlist> <listitem><para>call <xref linkend="function.PDOStatement-bindParam" /> 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 input-only parameter values</para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>input_parameters</parameter></term> <listitem> <para> An array of values with as many elements as there are bound parameters in the SQL statement being executed. </para> <para> You cannot bind multiple values to a single parameter; for example, you cannot bind two values to a single named parameter in an IN() clause. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <example><title>Execute a prepared statement with bound variables</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by binding PHP variables */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute(); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with an array of insert values (named parameters)</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by passing an array of insert values */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->execute(array(':calories' => $calories, ':colour' => $colour)); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with an array of insert values (placeholders)</title> <programlisting role='php'> <![CDATA[ <?php /* Execute a prepared statement by passing an array of insert values */ $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < ? AND colour = ?'); $sth->execute(array($calories, $colour)); ?> ]]> </programlisting> </example> <example><title>Execute a prepared statement with question mark placeholders</title> <programlisting role='php'> <![CDATA[ <?php /* 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> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-bindParam" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetch.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetch.xml +++ phpdoc/en/reference/pdo/pdostatement/fetch.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetch" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetch()</refname> <refpurpose> Fetches the next row from a result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>fetch</methodname> <methodparam choice="opt"><type>int</type><parameter>fetch_style</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>cursor_orientation</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>cursor_offset</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Fetches a row from a result set associated with a PDOStatement object. The <parameter>fetch_style</parameter> parameter determines how PDO returns the row. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>fetch_style</parameter></term> <listitem> <para> Controls how the next row will be returned to the caller. This value must be one of the <literal>PDO::FETCH_*</literal> constants, defaulting to <literal>PDO::FETCH_BOTH</literal>. <itemizedlist> <listitem><para> <literal>PDO::FETCH_ASSOC</literal>: returns an array indexed by column name as returned in your result set </para></listitem> <listitem><para> <literal>PDO::FETCH_BOTH</literal> (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set </para></listitem> <listitem><para> <literal>PDO::FETCH_BOUND</literal>: returns &true; and assigns the values of the columns in your result set to the PHP variables to which they were bound with the <xref linkend="function.PDOStatement-bindColumn" /> method </para></listitem> <listitem><para> <literal>PDO::FETCH_CLASS</literal>: returns a new instance of the requested class, mapping the columns of the result set to named properties in the class. If <parameter>fetch_style</parameter> includes PDO::FETCH_CLASSTYPE (e.g. <literal>PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE</literal>) then the name of the class is determined from a value of the first column. </para></listitem> <listitem><para> <literal>PDO::FETCH_INTO</literal>: updates an existing instance of the requested class, mapping the columns of the result set to named properties in the class </para></listitem> <listitem><para> <literal>PDO::FETCH_LAZY</literal>: combines <literal>PDO::FETCH_BOTH</literal> and <literal>PDO::FETCH_OBJ</literal>, creating the object variable names as they are accessed </para></listitem> <listitem><para> <literal>PDO::FETCH_NUM</literal>: returns an array indexed by column number as returned in your result set, starting at column 0 </para></listitem> <listitem><para> <literal>PDO::FETCH_OBJ</literal>: returns an anonymous object with property names that correspond to the column names returned in your result set </para></listitem> </itemizedlist> </para> </listitem> </varlistentry> <varlistentry> <term><parameter>cursor_orientation</parameter></term> <listitem> <para> For a PDOStatement object representing a scrollable cursor, this value determines which row will be returned to the caller. This value must be one of the <literal>PDO::FETCH_ORI_*</literal> constants, defaulting to <literal>PDO::FETCH_ORI_NEXT</literal>. To request a scrollable cursor for your PDOStatement object, you must set the <literal>PDO::ATTR_CURSOR</literal> attribute to <literal>PDO::CURSOR_SCROLL</literal> when you prepare the SQL statement with <xref linkend="function.PDO-prepare" />. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>offset</parameter></term> <listitem> <para> For a PDOStatement object representing a scrollable cursor for which the <literal>cursor_orientation</literal> parameter is set to <literal>PDO::FETCH_ORI_ABS</literal>, this value specifies the absolute number of the row in the result set that shall be fetched. </para> <para> For a PDOStatement object representing a scrollable cursor for which the <literal>cursor_orientation</literal> parameter is set to <literal>PDO::FETCH_ORI_REL</literal>, this value specifies the row to fetch relative to the cursor position before <xref linkend="function.PDOStatement-fetch" /> was called. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> The return value of this function on success depends on the fetch type. In all cases, &false; is returned on failure. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Fetching rows using different fetch styles</title> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Exercise PDOStatement::fetch styles */ print("PDO::FETCH_ASSOC: "); print("Return next row as an array indexed by column name\n"); $result = $sth->fetch(PDO::FETCH_ASSOC); print_r($result); print("\n"); print("PDO::FETCH_BOTH: "); print("Return next row as an array indexed by both column name and number\n"); $result = $sth->fetch(PDO::FETCH_BOTH); print_r($result); print("\n"); print("PDO::FETCH_LAZY: "); print("Return next row as an anonymous object with column names as properties\n"); $result = $sth->fetch(PDO::FETCH_LAZY); print_r($result); print("\n"); print("PDO::FETCH_OBJ: "); print("Return next row as an anonymous object with column names as properties\n"); $result = $sth->fetch(PDO::FETCH_OBJ); print $result->NAME; print("\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ PDO::FETCH_ASSOC: Return next row as an array indexed by column name Array ( [NAME] => apple [COLOUR] => red ) PDO::FETCH_BOTH: Return next row as an array indexed by both column name and number Array ( [NAME] => banana [0] => banana [COLOUR] => yellow [1] => yellow ) PDO::FETCH_LAZY: Return next row as an anonymous object with column names as properties PDORow Object ( [NAME] => orange [COLOUR] => orange ) PDO::FETCH_OBJ: Return next row as an anonymous object with column names as properties kiwi ]]> </screen> </example> <example><title>Fetching rows with a scrollable cursor</title> <programlisting role="php"> <![CDATA[ <?php function readDataForwards($dbh) { $sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY BET'; try { $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; print $data; } $stmt = null; } catch (PDOException $e) { print $e->getMessage(); } } function readDataBackwards($dbh) { $sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY bet'; try { $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST); do { $data = $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; print $data; } while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR)); $stmt = null; } catch (PDOException $e) { print $e->getMessage(); } } print "Reading forwards:\n"; readDataForwards($conn); print "Reading backwards:\n"; readDataBackwards($conn); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Reading forwards: 21 10 5 16 0 5 19 20 10 Reading backwards: 19 20 10 16 0 5 21 10 5 ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> <member><xref linkend="function.PDOStatement-fetchObject" /></member> <member><xref linkend="function.PDOStatement-setFetchMode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetchall.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetchall.xml +++ phpdoc/en/reference/pdo/pdostatement/fetchall.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetchAll" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetchAll()</refname> <refpurpose> Returns an array containing all of the result set rows </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>array</type><methodname>fetchAll</methodname> <methodparam choice="opt"><type>int</type><parameter>fetch_style</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>column_index</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>ctor_args</parameter></methodparam> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>fetch_style</parameter></term> <listitem> <para> Controls the contents of the returned array as documented in <xref linkend="function.PDOStatement-fetch" />. Defaults to <literal>PDO::FETCH_BOTH</literal>. </para> <para> To return an array consisting of all values of a single column from the result set, specify <literal>PDO::FETCH_COLUMN</literal>. You can specify which column you want with the <parameter>column-index</parameter> parameter. </para> <para> To fetch only the unique values of a single column from the result set, bitwise-OR <literal>PDO::FETCH_COLUMN</literal> with <literal>PDO::FETCH_UNIQUE</literal>. </para> <para> To return an associative array grouped by the values of a specified column, bitwise-OR <literal>PDO::FETCH_COLUMN</literal> with <literal>PDO::FETCH_GROUP</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>column_index</parameter></term> <listitem> <para> Returns the indicated 0-indexed column when the value of <parameter>fetch_style</parameter> is <literal>PDO::FETCH_COLUMN</literal>. Defaults to <literal>0</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>ctor_args</parameter></term> <listitem> <para> Arguments of custom class constructor. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDOStatement-fetchAll" /> returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties corresponding to each column name. </para> <para> Using this method to fetch large result sets will result in a heavy demand on system and possibly network resources. Rather than retrieving all of the data and manipulating it in PHP, consider using the database server to manipulate the result sets. For example, use the WHERE and SORT BY clauses in SQL to restrict results before retrieving and processing them with PHP. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Fetch all remaining rows in a result set</title> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch all of the remaining rows in the result set */ print("Fetch all of the remaining rows in the result set:\n"); $result = $sth->fetchAll(); print_r($result); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Fetch all of the remaining rows in the result set: Array ( [0] => Array ( [NAME] => pear [0] => pear [COLOUR] => green [1] => green ) [1] => Array ( [NAME] => watermelon [0] => watermelon [COLOUR] => pink [1] => pink ) ) ]]> </screen> </example> <example><title>Fetching all values of a single column from a result set</title> <para> The following example demonstrates how to return all of the values of a single column from a result set, even though the SQL statement itself may return multiple columns per row. </para> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch all of the values of the first column */ $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0); var_dump($result); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Array(3) ( [0] => string(5) => apple [1] => string(4) => pear [2] => string(10) => watermelon ) ]]> </screen> </example> <example><title>Grouping all values by a single column</title> <para> The following example demonstrates how to return an associative array grouped by the values of the specified column in the result set. The array contains three keys: values <literal>apple</literal> and <literal>pear</literal> are returned as arrays that contain two different colours, while <literal>watermelon</literal> is returned as an array that contains only one colour. </para> <programlisting role="php"> <![CDATA[ <?php $insert = $dbh->prepare("INSERT INTO fruit(name, colour) VALUES (?, ?)"); $insert->execute('apple', 'green'); $insert->execute('pear', 'yellow'); $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Group values by the first column */ var_dump($sth->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP)); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ array(3) { ["apple"]=> array(2) { [0]=> string(5) "green" [1]=> string(3) "red" } ["pear"]=> array(2) { [0]=> string(5) "green" [1]=> string(6) "yellow" } ["watermelon"]=> array(1) { [0]=> string(5) "green" } } ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-setFetchMode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetchcolumn.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetchcolumn.xml +++ phpdoc/en/reference/pdo/pdostatement/fetchcolumn.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetchColumn" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetchColumn()</refname> <refpurpose> Returns a single column from the next row of a result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>string</type><methodname>fetchColumn</methodname> <methodparam choice="opt"><type>int</type><parameter>column_number</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Returns a single column from the next row of a result set or &false; if there are no more rows. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>column_number</parameter></term> <listitem> <para> 0-indexed number of the column you wish to retrieve from the row. If no value is supplied, <xref linkend="function.PDOStatement-fetchColumn" /> fetches the first column. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> <xref linkend="function.PDOStatement-fetchColumn" /> returns a single column in the next row of a result set. </para> <warning> <para> There is no way to return another column from the same row if you use <xref linkend="function.PDOStatement-fetchColumn" /> to retrieve data. </para> </warning> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example><title>Return first column of the next row</title> <programlisting role="php"> <![CDATA[ <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch the first column from the next row in the result set */ print("Fetch the first column from the next row in the result set:\n"); $result = $sth->fetchColumn(); print("name = $result\n"); print("Fetch the second column from the next row in the result set:\n"); $result = $sth->fetchColumn(1); print("colour = $result\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Fetch the first column from the next row in the result set: name = lemon Fetch the second column from the next row in the result set: colour = red ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-query" /></member> <member><xref linkend="function.PDOStatement-fetch" /></member> <member><xref linkend="function.PDOStatement-fetchAll" /></member> <member><xref linkend="function.PDO-prepare" /></member> <member><xref linkend="function.PDOStatement-setFetchMode" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/fetchobject.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/fetchobject.xml +++ phpdoc/en/reference/pdo/pdostatement/fetchobject.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-fetchObject" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->fetchObject()</refname> <refpurpose>Fetches the next row and returns it as an object.</refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>fetchObject</methodname> <methodparam choice="opt"><type>string</type><parameter>class_name</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>ctor_args</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Fetches the next row and returns it as an object. This function is an alternative to <xref linkend="function.PDOStatement-fetch" /> with <constant>PDO::FETCH_CLASS</constant> or <constant>PDO::FETCH_OBJ</constant> style. </para> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>class_name</parameter></term> <listitem> <para> Name of the created class, defaults to <literal>stdClass</literal>. </para> </listitem> </varlistentry> <varlistentry> <term><parameter>ctor_args</parameter></term> <listitem> <para> Elements of this array are passed to the constructor. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns an instance of the required class with property names that correspond to the column names or &false; in case of an error. </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-fetch" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/getattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/getattribute.xml +++ phpdoc/en/reference/pdo/pdostatement/getattribute.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-getAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->getAttribute()</refname> <refpurpose> Retrieve a statement attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>mixed</type><methodname>getAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Gets an attribute of the statement. Currently, no generic attributes exist but only driver specific: <itemizedlist> <listitem><para><literal>PDO::ATTR_CURSOR_NAME</literal> (Firebird and ODBC specific): Get the name of cursor for <literal>UPDATE ... WHERE CURRENT OF</literal>. </para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns the attribute value. </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-getAttribute" /></member> <member><xref linkend="function.PDO-setAttribute" /></member> <member><xref linkend="function.PDOStatement-setAttribute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/getcolumnmeta.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/getcolumnmeta.xml +++ phpdoc/en/reference/pdo/pdostatement/getcolumnmeta.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-getColumnMeta" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->getColumnMeta()</refname> <refpurpose> Returns metadata for a column in a result set </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>array</type><methodname>getColumnMeta</methodname> <methodparam><type>int</type><parameter>column</parameter></methodparam> </methodsynopsis> </classsynopsis> &warn.experimental.func; <para> Retrieves the metadata for a 0-indexed column in a result set as an associative array. </para> <warning> <simpara> Not all PDO drivers support <xref linkend="function.PDOStatement-getColumnMeta" />. </simpara> </warning> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>column</parameter></term> <listitem> <para> The 0-indexed column in the result set. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns an associative array containing the following values representing the metadata for a single column: </para> <table> <title>Column metadata</title> <tgroup cols='2'> <colspec colname='c1'/> <colspec colname='c2'/> <thead> <row> <entry>Name</entry> <entry>Value</entry> </row> </thead> <tbody> <row> <entry><literal>native_type</literal></entry> <entry>The PHP native type used to represent the column value.</entry> </row> <row> <entry><literal>driver:decl_type</literal></entry> <entry>The SQL type used to represent the column value in the database. If the column in the result set is the result of a function, this value is not returned by <xref linkend="function.PDOStatement-getColumnMeta" />. </entry> </row> <row> <entry><literal>flags</literal></entry> <entry>Any flags set for this column.</entry> </row> <row> <entry><literal>name</literal></entry> <entry>The name of this column as returned by the database.</entry> </row> <row> <entry><literal>table</literal></entry> <entry>The name of this column's table as returned by the database.</entry> </row> <row> <entry><literal>len</literal></entry> <entry>The length of this column. Normally <literal>-1</literal> for types other than floating point decimals.</entry> </row> <row> <entry><literal>precision</literal></entry> <entry>The numeric precision of this column. Normally <literal>0</literal> for types other than floating point decimals.</entry> </row> <row> <entry><literal>pdo_type</literal></entry> <entry>The type of this column as represented by the <literal>PDO::PARAM_*</literal> constants.</entry> </row> </tbody> </tgroup> </table> <para> Returns &false; if the requested column does not exist in the result set, or if no result set exists. </para> </refsect1> <!-- Use when ERRORS exist <refsect1 role="errors"> &reftitle.errors; <para> When does this function throw E_* level errors, or exceptions? </para> </refsect1> --> <refsect1 role="changelog"> &reftitle.changelog; <para> <informaltable> <tgroup cols="2"> <thead> <row> <entry>&Version;</entry> <entry>&Description;</entry> </row> </thead> <tbody> <row> <entry>5.2.3</entry> <entry><literal>table</literal> field</entry> </row> </tbody> </tgroup> </informaltable> </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Retrieving column metadata</title> <para> The following example shows the results of retrieving the metadata for a single column generated by a function (COUNT) in a PDO_SQLITE driver. </para> <programlisting role="php"> <![CDATA[ <?php $select = $DB->query('SELECT COUNT(*) FROM fruit'); $meta = $select->getColumnMeta(0); var_dump($meta); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ array(6) { ["native_type"]=> string(7) "integer" ["flags"]=> array(0) { } ["name"]=> string(8) "COUNT(*)" ["len"]=> int(-1) ["precision"]=> int(0) ["pdo_type"]=> int(2) } ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-columnCount" /></member> <member><xref linkend="function.PDOStatement-rowCount" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/nextrowset.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/nextrowset.xml +++ phpdoc/en/reference/pdo/pdostatement/nextrowset.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-nextRowset" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->nextRowset()</refname> <refpurpose> Advances to the next rowset in a multi-rowset statement handle </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>nextRowset</methodname> <void/> </methodsynopsis> </classsynopsis> <para> Some database servers support stored procedures that return more than one rowset (also known as a result set). <xref linkend="function.PDOStatement-nextRowset" /> enables you to access the second and subsequent rowsets associated with a PDOStatement object. Each rowset can have a different set of columns from the preceding rowset. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Fetching multiple rowsets returned from a stored procedure</title> <para> The following example shows how to call a stored procedure, MULTIPLE_ROWSETS, that returns three rowsets. We use a do / while loop to loop over the <xref linkend="function.PDOStatement-nextRowset" /> method, which returns false and terminates the loop when no more rowsets can be returned. </para> <programlisting role="php"> <![CDATA[ <?php $sql = 'CALL multiple_rowsets()'; $stmt = $conn->query($sql); $i = 1; do { $rowset = $stmt->fetch(PDO::FETCH_NUM); if ($rowset) { printResultSet($rowset, $i); } $i++; } while ($stmt->nextRowset()); function printResultSet(&$rowset, $i) { print "Result set $i:\n"; foreach ($rowset as $row) { foreach ($row as $col) { print $col . "\t"; } print "\n"; } print "\n"; } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Result set 1: apple red banana yellow Result set 2: orange orange 150 banana yellow 175 Result set 3: lime green apple red banana yellow ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-columnCount" /></member> <member><xref linkend="function.PDOStatement-execute" /></member> <member><xref linkend="function.PDOStatement-getColumnMeta" /></member> <member><xref linkend="function.PDO-query" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/rowcount.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/rowcount.xml +++ phpdoc/en/reference/pdo/pdostatement/rowcount.xml <?xml version='1.0' encoding='iso-8859-1'?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-rowCount" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->rowCount()</refname> <refpurpose> Returns the number of rows affected by the last SQL statement </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>int</type><methodname>rowCount</methodname> <void/> </methodsynopsis> </classsynopsis> <para> <xref linkend="function.PDOStatement-rowCount" /> returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding <literal>PDOStatement</literal> object. </para> <para> If the last SQL statement executed by the associated <literal>PDOStatement</literal> was a SELECT statement, some databases may return the number of rows returned by that statement. However, this behaviour is not guaranteed for all databases and should not be relied on for portable applications. </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns the number of rows. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Return the number of deleted rows</title> <para> <xref linkend="function.PDOStatement-rowCount" /> returns the number of rows affected by a DELETE, INSERT, or UPDATE statement. </para> <programlisting role="php"> <![CDATA[ <?php /* Delete all rows from the FRUIT table */ $del = $dbh->prepare('DELETE FROM fruit'); $del->execute(); /* Return number of rows that were deleted */ print("Return number of rows that were deleted:\n"); $count = $del->rowCount(); print("Deleted $count rows.\n"); ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ Deleted 9 rows. ]]> </screen> </example> <example> <title>Counting rows returned by a SELECT statement</title> <para> For most databases, <xref linkend="function.PDOStatement-rowCount" /> does not return the number of rows affected by a SELECT statement. Instead, use <xref linkend="function.PDO-query" /> to issue a SELECT COUNT(*) statement with the same predicates as your intended SELECT statement, then use <xref linkend="function.PDOStatement-fetchColumn" /> to retrieve the number of rows that will be returned. Your application can then perform the correct action. </para> <programlisting role="php"> <![CDATA[ <?php $sql = "SELECT COUNT(*) FROM fruit WHERE calories > 100"; if ($res = $conn->query($sql)) { /* Check the number of rows that match the SELECT statement */ if ($res->fetchColumn() > 0) { /* Issue the real SELECT statement and work with the results */ $sql = "SELECT name FROM fruit WHERE calories > 100"; foreach ($conn->query($sql) as $row) { print "Name: " . $row['NAME'] . "\n"; } } /* No rows matched -- do something else */ else { print "No rows matched the query."; } } $res = null; $conn = null; ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple banana orange pear ]]> </screen> </example> </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDOStatement-columnCount" /></member> <member><xref linkend="function.PDOStatement-fetchColumn" /></member> <member><xref linkend="function.PDO-query" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/setattribute.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/setattribute.xml +++ phpdoc/en/reference/pdo/pdostatement/setattribute.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-setAttribute" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->setAttribute()</refname> <refpurpose> Set a statement attribute </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setAttribute</methodname> <methodparam><type>int</type><parameter>attribute</parameter></methodparam> <methodparam><type>mixed</type><parameter>value</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> Sets an attribute on the statement. Currently, no generic attributes are set but only driver specific: <itemizedlist> <listitem><para><literal>PDO::ATTR_CURSOR_NAME</literal> (Firebird and ODBC specific): Set the name of cursor for <literal>UPDATE ... WHERE CURRENT OF</literal>. </para></listitem> </itemizedlist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> &return.success; </para> </refsect1> <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><xref linkend="function.PDO-getAttribute" /></member> <member><xref linkend="function.PDO-setAttribute" /></member> <member><xref linkend="function.PDOStatement-getAttribute" /></member> </simplelist> </para> </refsect1> </refentry> <!-- 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 --> http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/pdo/pdostatement/setfetchmode.xml?view=markup&rev=1.1 Index: phpdoc/en/reference/pdo/pdostatement/setfetchmode.xml +++ phpdoc/en/reference/pdo/pdostatement/setfetchmode.xml <?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.1 $ --> <refentry xml:id="function.PDOStatement-setFetchMode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>PDOStatement->setFetchMode()</refname> <refpurpose> Set the default fetch mode for this statement </refpurpose> </refnamediv> <refsect1 role="description"> &reftitle.description; <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>mode</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>PDO::FETCH_COLUMN</parameter></methodparam> <methodparam><type>int</type><parameter>colno</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>PDO::FETCH_CLASS</parameter></methodparam> <methodparam><type>string</type><parameter>classname</parameter></methodparam> <methodparam><type>array</type><parameter>ctorargs</parameter></methodparam> </methodsynopsis> </classsynopsis> <classsynopsis> <ooclass><classname>PDOStatement</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>setFetchMode</methodname> <methodparam><type>int</type><parameter>PDO::FETCH_INTO</parameter></methodparam> <methodparam><type>object</type><parameter>object</parameter></methodparam> </methodsynopsis> </classsynopsis> </refsect1> <refsect1 role="parameters"> &reftitle.parameters; <para> <variablelist> <varlistentry> <term><parameter>mode</parameter></term> <listitem> <para> The fetch mode must be one of the <literal>PDO::FETCH_*</literal> constants. </para> </listitem> </varlistentry> </variablelist> </para> </refsect1> <refsect1 role="returnvalues"> &reftitle.returnvalues; <para> Returns <literal>1</literal> on success or &false; on failure. </para> </refsect1> <refsect1 role="examples"> &reftitle.examples; <para> <example> <title>Setting the fetch mode</title> <para> The following example demonstrates how <xref linkend="function.PDOStatement-setFetchMode" /> changes the default fetch mode for a PDOStatement object. </para> <programlisting role="php"> <![CDATA[ <?php $sql = 'SELECT name, colour, calories FROM fruit'; try { $stmt = $dbh->query($sql); $result = $stmt->setFetchMode(PDO::FETCH_NUM); while ($row = $stmt->fetch()) { print $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n"; } } catch (PDOException $e) { print $e->getMessage(); } ?> ]]> </programlisting> &example.outputs; <screen> <![CDATA[ apple red 150 banana yellow 250 orange orange 300 kiwi brown 75 lemon yellow 25 pear green 150 watermelon pink 90 ]]> </screen> </example> </para> </refsect1> <!-- Use when adding See Also links <refsect1 role="seealso"> &reftitle.seealso; <para> <simplelist> <member><function></function></member> <member>Or <link linkend="somethingelse">something else</link></member> </simplelist> </para> </refsect1> --> </refentry> <!-- 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 -->