1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.application.available-resources.db">
4 <title>Zend_Application_Resource_Db</title>
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
17 The following configuration keys are recognized:
23 <emphasis><property>adapter</property></emphasis>: <classname>Zend_Db</classname>
30 <emphasis><property>params</property></emphasis>: associative array of configuration
31 parameters to use when retrieving the adapter instance.
37 <emphasis><property>isDefaultTableAdapter</property></emphasis>: whether or not to
38 establish this adapter as the default table adapter.
43 <example id="zend.application.available-resources.db.configExample">
44 <title>Sample DB adapter resource configuration</title>
47 Below is an example <acronym>INI</acronym> configuration that can be used to initialize
51 <programlisting language="ini"><![CDATA[
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
63 <title>Retrieving the Adapter instance</title>
66 If you choose not to make the adapter instantiated with this
67 resource the default table adapter, how do you retrieve the adapter
72 As with any resource plugin, you can fetch the DB resource plugin
76 <programlisting language="php"><![CDATA[
77 $resource = $bootstrap->getPluginResource('db');
81 Once you have the resource object, you can fetch the DB adapter
82 using the <methodname>getDbAdapter()</methodname> method:
85 <programlisting language="php"><![CDATA[
86 $db = $resource->getDbAdapter();