Zend_Application-AvailableResources-Db.xml 2.8 KB

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