File: Zend_Application-AvailableResources-Multidb.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (85 lines) | stat: -rw-r--r-- 3,451 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect2 id="zend.application.available-resources.multidb">
    <title>Zend_Application_Resource_Multidb</title>

    <para>
        <classname>Zend_Application_Resource_Multidb</classname> is used to initialize
        multiple Database connections. You can use the same options as you can with
        the <link linkend="zend.application.available-resources.db">Db Resource Plugin</link>.
        However, for specifying a default connection, you can also use the 'default' directive.
    </para>

    <example id="zend.application.available-resources.multidb.configexample">
        <title>Setting up multiple Db Connections</title>

        <para>
            Below is an example <acronym>INI</acronym> configuration that can be used to initialize
            two Db Connections.
        </para>

        <programlisting language="ini"><![CDATA[
[production]
resources.multidb.db1.adapter = "pdo_mysql"
resources.multidb.db1.host = "localhost"
resources.multidb.db1.username = "webuser"
resources.multidb.db1.password = "XXXX"
resources.multidb.db1.dbname = "db1"

resources.multidb.db2.adapter = "pdo_pgsql"
resources.multidb.db2.host = "example.com"
resources.multidb.db2.username = "dba"
resources.multidb.db2.password = "notthatpublic"
resources.multidb.db2.dbname = "db2"
resources.multidb.db2.default = true
]]></programlisting>
    </example>

    <example id="zend.application.available-resources.multidb.retrieveSpecificDb">
        <title>Retrieving a specific database adapter</title>

        <para>
            When using this resource plugin you usually will want to retrieve
            a specific database. This can be done by using the resource's
            <methodname>getDb()</methodname>. The method
            <methodname>getDb()</methodname> returns an instance of a class that
            extends <classname>Zend_Db_Adapter_Abstract</classname>. If you have not
            set a default database, an exception will be thrown when this method
            is called without specifying a parameter.
         </para>

        <programlisting language="php"><![CDATA[
$resource = $bootstrap->getPluginResource('multidb');
$db1 = $resource->getDb('db1');
$db2 = $resource->getDb('db2');
$defaultDb = $resource->getDb();
]]></programlisting>
    </example>

    <example id="zend.application.available-resources.multidb.retrieveDefaultDb">
        <title>Retrieving the default database adapter</title>

        <para>
            Additionally, you can retrieve the default database adapter
            by using the method <methodname>getDefaultDb()</methodname>.
            If you have not set a default adapter, the first configured db
            adapter will be returned. Unless you specify <constant>FALSE</constant>
            as first parameter, then <constant>NULL</constant>
            will be returned when no default database adapter was set.
         </para>

        <para>
            Below is an example that assumes the Multidb resource plugin has been configured
            with the <acronym>INI</acronym> sample above:
        </para>

        <programlisting language="php"><![CDATA[
$resource = $bootstrap->getPluginResource('multidb');
$db2 = $resource->getDefaultDb();

// Same config, but now without a default db:
$db1 = $resource->getDefaultDb();
$null = $resource->getDefaultDb(false); // null
]]></programlisting>
    </example>
</sect2>