|
1 <?php |
|
2 |
|
3 namespace Doctrine\DBAL\Driver\PDOPgSql; |
|
4 |
|
5 use Doctrine\DBAL\Platforms; |
|
6 |
|
7 /** |
|
8 * Driver that connects through pdo_pgsql. |
|
9 * |
|
10 * @since 2.0 |
|
11 */ |
|
12 class 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 } |