| 1 |
<?php |
|---|
| 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 |
class sfPostgreSQLDatabase extends sfDatabase |
|---|
| 31 |
{ |
|---|
| 32 |
|
|---|
| 33 |
* Connects to the database. |
|---|
| 34 |
* |
|---|
| 35 |
* @throws <b>sfDatabaseException</b> If a connection could not be created |
|---|
| 36 |
*/ |
|---|
| 37 |
public function connect() |
|---|
| 38 |
{ |
|---|
| 39 |
$database = $this->getParameter('database'); |
|---|
| 40 |
$host = $this->getParameter('host'); |
|---|
| 41 |
$password = $this->getParameter('password'); |
|---|
| 42 |
$port = $this->getParameter('port'); |
|---|
| 43 |
$username = $this->getParameter('username'); |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
$string = ($database != null ? (' dbname=' .$database) : ''). |
|---|
| 47 |
($host != null ? (' host=' .$host) : ''). |
|---|
| 48 |
($password != null ? (' password=' .$password) : ''). |
|---|
| 49 |
($port != null ? (' port=' .$port) : ''). |
|---|
| 50 |
($username != null ? (' user=' .$username) : ''); |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
$persistent = $this->getParameter('persistent', false); |
|---|
| 54 |
$connect = $persistent ? 'pg_pconnect' : 'pg_connect'; |
|---|
| 55 |
|
|---|
| 56 |
$this->connection = @$connect($string); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
if ($this->connection === false) |
|---|
| 60 |
{ |
|---|
| 61 |
|
|---|
| 62 |
throw new sfDatabaseException('Failed to create a PostgreSQLDatabase connection.'); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
// to the resource |
|---|
| 67 |
$this->resource = $this->connection; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
* Executes the shutdown procedure. |
|---|
| 72 |
* |
|---|
| 73 |
* @throws <b>sfDatabaseException</b> If an error occurs while shutting down this database |
|---|
| 74 |
*/ |
|---|
| 75 |
public function shutdown() |
|---|
| 76 |
{ |
|---|
| 77 |
if ($this->connection != null) |
|---|
| 78 |
{ |
|---|
| 79 |
@pg_close($this->connection); |
|---|
| 80 |
} |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|