<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.application.available-resources.db">
    <title>Zend_Application_Resource_Db</title>

    <para>
        <classname>Zend_Application_Resource_Db</classname> will initialize a
        <classname>Zend_Db</classname> adapter based on the options passed to it. By
        default, it also sets the adapter as the default adapter for use with
        <classname>Zend_Db_Table</classname>. If you want to use mutliple databases
        simultaneously, you can use the <link
        linkend="zend.application.available-resources.multidb">Multidb Resource
        Plugin</link>.
    </para>

    <para>
        The following configuration keys are recognized:
    </para>

    <itemizedlist>
        <listitem>
            <para>
                <emphasis><property>adapter</property></emphasis>: <classname>Zend_Db</classname>
                adapter type.
            </para>
        </listitem>

        <listitem>
            <para>
                <emphasis><property>params</property></emphasis>: associative array of configuration
                parameters to use when retrieving the adapter instance.
            </para>
        </listitem>

        <listitem>
            <para>
                <emphasis><property>isDefaultTableAdapter</property></emphasis>: whether or not to
                establish this adapter as the default table adapter.
            </para>
        </listitem>

        <listitem>
            <para>
                <emphasis><property>defaultMetadataCache</property></emphasis>: the name of the
                cache template or an instance of <classname>Zend_Cache_Core</classname> to use as
                metadata cache for <classname>Zend_Db_Table</classname>.
            </para>
        </listitem>
    </itemizedlist>

    <example id="zend.application.available-resources.db.configExample">
        <title>Sample DB adapter resource configuration</title>

        <para>
            Below is an example <acronym>INI</acronym> configuration that can be used to initialize
            the DB resource.
        </para>

        <programlisting language="ini"><![CDATA[
[production]
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "webuser"
resources.db.params.password = "XXXXXXX"
resources.db.params.dbname = "test"
resources.db.isDefaultTableAdapter = true

; Optionally you can also the cache template to use for metadata caching:
resources.db.defaultMetadataCache = "database"
]]></programlisting>
    </example>

    <note>
        <title>Retrieving the Adapter instance</title>

        <para>
            If you choose not to make the adapter instantiated with this
            resource the default table adapter, how do you retrieve the adapter
            instance?
        </para>

        <para>
            As with any resource plugin, you can fetch the DB resource plugin
            from your bootstrap:
        </para>

        <programlisting language="php"><![CDATA[
$resource = $bootstrap->getPluginResource('db');
]]></programlisting>

        <para>
            Once you have the resource object, you can fetch the DB adapter
            using the <methodname>getDbAdapter()</methodname> method:
        </para>

        <programlisting language="php"><![CDATA[
$db = $resource->getDbAdapter();
]]></programlisting>
    </note>
</sect2>
