[MANUAL] English:
[zend.git] / documentation / manual / en / module_specs / Zend_Application-AvailableResources-Db.xml
blobc31c7b3b56ea3c4568bf15e432bbb92f5d268db3
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- Reviewed: no -->
3 <sect2 id="zend.application.available-resources.db">
4     <title>Zend_Application_Resource_Db</title>
6     <para>
7         <classname>Zend_Application_Resource_Db</classname> will initialize a
8         <classname>Zend_Db</classname> adapter based on the options passed to it. By
9         default, it also sets the adapter as the default adapter for use with
10         <classname>Zend_Db_Table</classname>. If you want to use mutliple databases
11         simultaneously, you can use the <link
12         linkend="zend.application.available-resources.multidb">Multidb Resource
13         Plugin</link>.
14     </para>
16     <para>
17         The following configuration keys are recognized:
18     </para>
20     <itemizedlist>
21         <listitem>
22             <para>
23                 <emphasis><property>adapter</property></emphasis>: <classname>Zend_Db</classname>
24                 adapter type.
25             </para>
26         </listitem>
28         <listitem>
29             <para>
30                 <emphasis><property>params</property></emphasis>: associative array of configuration
31                 parameters to use when retrieving the adapter instance.
32             </para>
33         </listitem>
35         <listitem>
36             <para>
37                 <emphasis><property>isDefaultTableAdapter</property></emphasis>: whether or not to
38                 establish this adapter as the default table adapter.
39             </para>
40         </listitem>
41     </itemizedlist>
43     <example id="zend.application.available-resources.db.configExample">
44         <title>Sample DB adapter resource configuration</title>
46         <para>
47             Below is an example <acronym>INI</acronym> configuration that can be used to initialize
48             the DB resource.
49         </para>
51         <programlisting language="ini"><![CDATA[
52 [production]
53 resources.db.adapter = "pdo_mysql"
54 resources.db.params.host = "localhost"
55 resources.db.params.username = "webuser"
56 resources.db.params.password = "XXXXXXX"
57 resources.db.params.dbname = "test"
58 resources.db.isDefaultTableAdapter = true
59 ]]></programlisting>
60     </example>
62     <note>
63         <title>Retrieving the Adapter instance</title>
65         <para>
66             If you choose not to make the adapter instantiated with this
67             resource the default table adapter, how do you retrieve the adapter
68             instance?
69         </para>
71         <para>
72             As with any resource plugin, you can fetch the DB resource plugin
73             from your bootstrap:
74         </para>
76         <programlisting language="php"><![CDATA[
77 $resource = $bootstrap->getPluginResource('db');
78 ]]></programlisting>
80         <para>
81             Once you have the resource object, you can fetch the DB adapter
82             using the <methodname>getDbAdapter()</methodname> method:
83         </para>
85         <programlisting language="php"><![CDATA[
86 $db = $resource->getDbAdapter();
87 ]]></programlisting>
88     </note>
89 </sect2>