Zend_Application-AvailableResources-Db.xml 2.9 KB

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