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

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

collaborator page

File size: 3.1 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\PDOOracle;
21
22use Doctrine\DBAL\Platforms;
23
24/**
25 * PDO Oracle driver
26 *
27 * WARNING: This driver gives us segfauls in our testsuites on CLOB and other
28 * stuff. PDO Oracle is not maintained by Oracle or anyone in the PHP community,
29 * which leads us to the recommendation to use the "oci8" driver to connect
30 * to Oracle instead.
31 */
32class Driver implements \Doctrine\DBAL\Driver
33{
34    public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
35    {
36        return new \Doctrine\DBAL\Driver\PDOConnection(
37            $this->_constructPdoDsn($params),
38            $username,
39            $password,
40            $driverOptions
41        );
42    }
43
44    /**
45     * Constructs the Oracle PDO DSN.
46     *
47     * @return string  The DSN.
48     */
49    private function _constructPdoDsn(array $params)
50    {
51        $dsn = 'oci:';
52        if (isset($params['host'])) {
53            $dsn .= 'dbname=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)' .
54                   '(HOST=' . $params['host'] . ')';
55
56            if (isset($params['port'])) {
57                $dsn .= '(PORT=' . $params['port'] . ')';
58            } else {
59                $dsn .= '(PORT=1521)';
60            }
61
62            if (isset($params['service']) && $params['service'] == true) {
63                $dsn .= '))(CONNECT_DATA=(SERVICE_NAME=' . $params['dbname'] . ')))';
64            } else {
65                $dsn .= '))(CONNECT_DATA=(SID=' . $params['dbname'] . ')))';
66            }
67        } else {
68            $dsn .= 'dbname=' . $params['dbname'];
69        }
70
71        if (isset($params['charset'])) {
72            $dsn .= ';charset=' . $params['charset'];
73        }
74
75        return $dsn;
76    }
77
78    public function getDatabasePlatform()
79    {
80        return new \Doctrine\DBAL\Platforms\OraclePlatform();
81    }
82
83    public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
84    {
85        return new \Doctrine\DBAL\Schema\OracleSchemaManager($conn);
86    }
87
88    public function getName()
89    {
90        return 'pdo_oracle';
91    }
92
93    public function getDatabase(\Doctrine\DBAL\Connection $conn)
94    {
95        $params = $conn->getParams();
96        return $params['user'];
97    }
98}
Note: See TracBrowser for help on using the repository browser.