Zend_Application-AvailableResources-Db.xml 2.5 KB

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