Zend_Application-AvailableResources-Db.xml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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>
  5. <para>
  6. <classname>Zend_Application_Resource_Db</classname> will initialize a
  7. <classname>Zend_Db</classname> adapter based on the options passed to it. By
  8. default, it also sets the adapter as the default adapter for use with
  9. <classname>Zend_Db_Table</classname>.
  10. </para>
  11. <para>
  12. The following configuration keys are recognized:
  13. </para>
  14. <itemizedlist>
  15. <listitem><para>
  16. <emphasis><property>adapter</property></emphasis>: <classname>Zend_Db</classname>
  17. adapter type.
  18. </para></listitem>
  19. <listitem><para>
  20. <emphasis><property>params</property></emphasis>: associative array of configuration
  21. parameters to use when retrieving the adapter instance.
  22. </para></listitem>
  23. <listitem><para>
  24. <emphasis><property>isDefaultTableAdapter</property></emphasis>: whether or not to
  25. establish this adapter as the default table adapter.
  26. </para></listitem>
  27. </itemizedlist>
  28. <example id="zend.application.available-resources.db.configExample">
  29. <title>Sample DB adapter resource configuration</title>
  30. <para>
  31. Below is an example <acronym>INI</acronym> configuration that can be used to initialize
  32. the DB resource.
  33. </para>
  34. <programlisting language="ini"><![CDATA[
  35. [production]
  36. resources.db.adapter = "pdo_mysql"
  37. resources.db.params.host = "localhost"
  38. resources.db.params.username = "webuser"
  39. resources.db.params.password = "XXXXXXX"
  40. resources.db.params.dbname = "test"
  41. resources.db.isDefaultTableAdapter = true
  42. ]]></programlisting>
  43. </example>
  44. <note>
  45. <title>Retrieving the Adapter instance</title>
  46. <para>
  47. If you choose not to make the adapter instantiated with this
  48. resource the default table adapter, how do you retrieve the adapter
  49. instance?
  50. </para>
  51. <para>
  52. As with any resource plugin, you can fetch the DB resource plugin
  53. from your bootstrap:
  54. </para>
  55. <programlisting language="php"><![CDATA[
  56. $resource = $bootstrap->getPluginResource('db');
  57. ]]></programlisting>
  58. <para>
  59. Once you have the resource object, you can fetch the DB adapter
  60. using the <methodname>getDbAdapter()</methodname> method:
  61. </para>
  62. <programlisting language="php"><![CDATA[
  63. $db = $resource->getDbAdapter();
  64. ]]></programlisting>
  65. </note>
  66. </sect2>