dbs Sat Nov 13 17:28:28 2004 EDT
Modified files: /phpdoc/en/reference/pdo reference.xml /phpdoc/en/reference/pdo/functions PDO-construct.xml Log: Add more PDO driver and constructor information http://cvs.php.net/diff.php/phpdoc/en/reference/pdo/reference.xml?r1=1.6&r2=1.7&ty=u Index: phpdoc/en/reference/pdo/reference.xml diff -u phpdoc/en/reference/pdo/reference.xml:1.6 phpdoc/en/reference/pdo/reference.xml:1.7 --- phpdoc/en/reference/pdo/reference.xml:1.6 Thu Nov 11 11:57:17 2004 +++ phpdoc/en/reference/pdo/reference.xml Sat Nov 13 17:28:27 2004 @@ -1,8 +1,8 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.6 $ --> +<!-- $Revision: 1.7 $ --> <!-- Generated by xml_proto.php v2.1. Found in /scripts directory of phpdoc. --> <reference id="ref.pdo"> - <title>pdo Functions</title> + <title>PDO Functions</title> <titleabbrev>pdo</titleabbrev> <partintro> @@ -13,7 +13,10 @@ The PDO extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific - features as regular extension functions. + features as regular extension functions. Note that you cannot + perform any database functions using the PDO extension by + itself; you must use a <link linkend="pdo.drivers">database-specific + PDO driver</link> to access a database server. </para> </section> <section id="pdo.installation"> @@ -57,6 +60,45 @@ </screen> </para> </section> + <section id="pdo.drivers"> + <title>PDO Drivers</title> + <para> + The following drivers currently implement the PDO interface: + <itemizedlist> + <listitem> + <para> + PDO_FIREBIRD - Firebird/Interbase 6 + </para> + </listitem> + <listitem> + <para> + PDO_MYSQL - MySQL 3.x/4.0 + </para> + </listitem> + <listitem> + <para> + PDO_OCI - Oracle Call Interface + </para> + </listitem> + <listitem> + <para> + PDO_ODBC - ODBC v3 (IBM DB2 and unixODBC) + </para> + </listitem> + <listitem> + <para> + PDO_PGSQL - PostgreSQL + </para> + </listitem> + <listitem> + <para> + PDO_SQLITE - SQLite 3.x + </para> + </listitem> + </itemizedlist> + </para> + </section> + <section id='pdo.classes'> &reftitle.classes; <section id='pdo.class.PDO'> http://cvs.php.net/diff.php/phpdoc/en/reference/pdo/functions/PDO-construct.xml?r1=1.3&r2=1.4&ty=u Index: phpdoc/en/reference/pdo/functions/PDO-construct.xml diff -u phpdoc/en/reference/pdo/functions/PDO-construct.xml:1.3 phpdoc/en/reference/pdo/functions/PDO-construct.xml:1.4 --- phpdoc/en/reference/pdo/functions/PDO-construct.xml:1.3 Fri Nov 12 08:16:16 2004 +++ phpdoc/en/reference/pdo/functions/PDO-construct.xml Sat Nov 13 17:28:28 2004 @@ -1,5 +1,5 @@ <?xml version='1.0' encoding='iso-8859-1'?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <refentry id="function.PDO-construct"> <refnamediv> <refname>PDO::__construct</refname> @@ -13,12 +13,132 @@ <type>PDO</type><methodname>PDO::__construct</methodname> <methodparam><type>string</type><parameter>dsn</parameter></methodparam> <methodparam><type>string</type><parameter>username</parameter></methodparam> - <methodparam><type>string</type><parameter>passwd</parameter></methodparam> + <methodparam><type>string</type><parameter>password</parameter></methodparam> <methodparam choice="opt"><type>array</type><parameter>driver_opts</parameter></methodparam> </methodsynopsis> + &warn.experimental.func; + <para> + Creates a PDO instance to represent a connection to the requested + database. The <parameter>dsn</parameter> parameter supports three + different methods of specifying the arguments required to create + a database connection: + <variablelist> + <varlistentry><term>Driver invocation</term> + <listitem> + <para> + <parameter>dsn</parameter> consists of the PDO driver name, followed + by a colon, followed by the PDO driver-specific connection syntax. + For example, <userinput>'odbc:DSN=SAMPLE;UID=db2inst1;PWD=ibmdb2'</userinput> + would create a PDO_ODBC connection to an ODBC database, while + <userinput>'mysql:host=127.0.0.1;dbname=testdb'</userinput> would create + a PDO_MYSQL connection to a MySQL database. + </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> + </listitem> + </varlistentry> + <varlistentry><term>Aliasing</term> + <listitem> + <para> + <parameter>dsn</parameter> consists of a name + <parameter>name</parameter> that maps to + <literal>pdo.dsn.<parameter>name</parameter></literal> in &php.ini; + defining the DSN string. <parameter>name</parameter> can not contain + a colon. + </para> + </listitem> + </varlistentry> + </variablelist> + If <parameter>username</parameter> or <parameter>password</parameter> + are not required to complete the connection, you must pass empty strings + or the constructor will throw a PDOException exception. + </para> + <example><title>Create a PDO instance via driver invocation</title> + <programlisting role="php"> +<![CDATA[ +<?php +/* Connect to an ODBC database using driver invocation - &warn.undocumented.func; +$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> + <programlisting> +<![CDATA[ +odbc:DSN=SAMPLE;UID=db2inst1;PWD=password +]]> + </programlisting> + <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>: + <screen>pdo.dsn.mydb=mysql:dbname=testdb;host=127.0.0.1</screen> + </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> </refsect1> </refentry>