source: pro-violet-viettel/sourcecode/application/libraries/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @ 345

Last change on this file since 345 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 3.8 KB
Line 
1<?php
2/*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 *
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the LGPL. For more information, see
17 * <http://www.doctrine-project.org>.
18*/
19
20namespace Doctrine\DBAL\Driver\IBMDB2;
21
22use Doctrine\DBAL\Driver,
23    Doctrine\DBAL\Connection;
24
25/**
26 * IBM DB2 Driver
27 *
28 * @since 2.0
29 * @author Benjamin Eberlei <kontakt@beberlei.de>
30 */
31class DB2Driver implements Driver
32{
33    /**
34     * Attempts to create a connection with the database.
35     *
36     * @param array $params All connection parameters passed by the user.
37     * @param string $username The username to use when connecting.
38     * @param string $password The password to use when connecting.
39     * @param array $driverOptions The driver options to use when connecting.
40     * @return Doctrine\DBAL\Driver\Connection The database connection.
41     */
42    public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
43    {
44        if ( ! isset($params['protocol'])) {
45            $params['protocol'] = 'TCPIP';
46        }
47
48        if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') {
49            // if the host isn't localhost, use extended connection params
50            $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
51                     ';DATABASE=' . $params['dbname'] .
52                     ';HOSTNAME=' . $params['host'] .
53                     ';PROTOCOL=' . $params['protocol'] .
54                     ';UID='      . $username .
55                     ';PWD='      . $password .';';
56            if (isset($params['port'])) {
57                $params['dbname'] .= 'PORT=' . $params['port'];
58            }
59
60            $username = null;
61            $password = null;
62        }
63
64        return new DB2Connection($params, $username, $password, $driverOptions);
65    }
66
67    /**
68     * Gets the DatabasePlatform instance that provides all the metadata about
69     * the platform this driver connects to.
70     *
71     * @return Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
72     */
73    public function getDatabasePlatform()
74    {
75        return new \Doctrine\DBAL\Platforms\DB2Platform;
76    }
77
78    /**
79     * Gets the SchemaManager that can be used to inspect and change the underlying
80     * database schema of the platform this driver connects to.
81     *
82     * @param  Doctrine\DBAL\Connection $conn
83     * @return Doctrine\DBAL\SchemaManager
84     */
85    public function getSchemaManager(Connection $conn)
86    {
87        return new \Doctrine\DBAL\Schema\DB2SchemaManager($conn);
88    }
89
90    /**
91     * Gets the name of the driver.
92     *
93     * @return string The name of the driver.
94     */
95    public function getName()
96    {
97        return 'ibm_db2';
98    }
99
100    /**
101     * Get the name of the database connected to for this driver.
102     *
103     * @param  Doctrine\DBAL\Connection $conn
104     * @return string $database
105     */
106    public function getDatabase(\Doctrine\DBAL\Connection $conn)
107    {
108        $params = $conn->getParams();
109        return $params['dbname'];
110    }
111}
Note: See TracBrowser for help on using the repository browser.