| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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>.
- </para>
- <para>
- The following configuration keys are recognized:
- </para>
- <itemizedlist>
- <listitem><para>
- <emphasis>adapter</emphasis>: <classname>Zend_Db</classname> adapter type.
- </para></listitem>
- <listitem><para>
- <emphasis>params</emphasis>: associative array of configuration
- parameters to use when retrieving the adapter instance.
- </para></listitem>
- <listitem><para>
- <emphasis>isDefaultTableAdapter</emphasis>: whether or not to establish this
- adapter as the default table adapter.
- </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
- ]]></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>
|