Zend_Application-AvailableResources-Db.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. <listitem>
  37. <para>
  38. <emphasis><property>defaultMetadataCache</property></emphasis>: the name of the
  39. cache template or an instance of <classname>Zend_Cache_Core</classname> to use as
  40. metadata cache for <classname>Zend_Db_Table</classname>.
  41. </para>
  42. </listitem>
  43. </itemizedlist>
  44. <example id="zend.application.available-resources.db.configExample">
  45. <title>Sample DB adapter resource configuration</title>
  46. <para>
  47. Below is an example <acronym>INI</acronym> configuration that can be used to initialize
  48. the DB resource.
  49. </para>
  50. <programlisting language="ini"><![CDATA[
  51. [production]
  52. resources.db.adapter = "pdo_mysql"
  53. resources.db.params.host = "localhost"
  54. resources.db.params.username = "webuser"
  55. resources.db.params.password = "XXXXXXX"
  56. resources.db.params.dbname = "test"
  57. resources.db.isDefaultTableAdapter = true
  58. ; Optionally you can also the cache template to use for metadata caching:
  59. resources.db.defaultMetadataCache = "database"
  60. ]]></programlisting>
  61. </example>
  62. <note>
  63. <title>Retrieving the Adapter instance</title>
  64. <para>
  65. If you choose not to make the adapter instantiated with this
  66. resource the default table adapter, how do you retrieve the adapter
  67. instance?
  68. </para>
  69. <para>
  70. As with any resource plugin, you can fetch the DB resource plugin
  71. from your bootstrap:
  72. </para>
  73. <programlisting language="php"><![CDATA[
  74. $resource = $bootstrap->getPluginResource('db');
  75. ]]></programlisting>
  76. <para>
  77. Once you have the resource object, you can fetch the DB adapter
  78. using the <methodname>getDbAdapter()</methodname> method:
  79. </para>
  80. <programlisting language="php"><![CDATA[
  81. $db = $resource->getDbAdapter();
  82. ]]></programlisting>
  83. </note>
  84. </sect2>