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

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

collaborator page

File size: 1.7 KB
Line 
1<?php
2
3namespace Doctrine\DBAL\Driver\PDOPgSql;
4
5use Doctrine\DBAL\Platforms;
6
7/**
8 * Driver that connects through pdo_pgsql.
9 *
10 * @since 2.0
11 */
12class Driver implements \Doctrine\DBAL\Driver
13{
14    /**
15     * Attempts to connect to the database and returns a driver connection on success.
16     *
17     * @return Doctrine\DBAL\Driver\Connection
18     */
19    public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
20    {
21        return new \Doctrine\DBAL\Driver\PDOConnection(
22            $this->_constructPdoDsn($params),
23            $username,
24            $password,
25            $driverOptions
26        );
27    }
28
29    /**
30     * Constructs the Postgres PDO DSN.
31     *
32     * @return string The DSN.
33     */
34    private function _constructPdoDsn(array $params)
35    {
36        $dsn = 'pgsql:';
37        if (isset($params['host']) && $params['host'] != '') {
38            $dsn .= 'host=' . $params['host'] . ' ';
39        }
40        if (isset($params['port']) && $params['port'] != '') {
41            $dsn .= 'port=' . $params['port'] . ' ';
42        }
43        if (isset($params['dbname'])) {
44            $dsn .= 'dbname=' . $params['dbname'] . ' ';
45        }
46
47        return $dsn;
48    }
49
50    public function getDatabasePlatform()
51    {
52        return new \Doctrine\DBAL\Platforms\PostgreSqlPlatform();
53    }
54
55    public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
56    {
57        return new \Doctrine\DBAL\Schema\PostgreSqlSchemaManager($conn);
58    }
59
60    public function getName()
61    {
62        return 'pdo_pgsql';
63    }
64
65    public function getDatabase(\Doctrine\DBAL\Connection $conn)
66    {
67        $params = $conn->getParams();
68        return $params['dbname'];
69    }
70}
Note: See TracBrowser for help on using the repository browser.