|
Revision 7791, 2.1 kB
(checked in by fabien, 4 years ago)
|
updated Sean Kerr email address
|
- Property svn:mime-type set to
text/x-php
- Property svn:eol-style set to
native
- Property svn:keywords set to
Id Rev Date
|
| Line | |
|---|
| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
class sfPDODatabase extends sfDatabase |
|---|
| 23 |
{ |
|---|
| 24 |
|
|---|
| 25 |
* Connects to the database. |
|---|
| 26 |
* |
|---|
| 27 |
* @throws <b>sfDatabaseException</b> If a connection could not be created |
|---|
| 28 |
*/ |
|---|
| 29 |
public function connect() |
|---|
| 30 |
{ |
|---|
| 31 |
|
|---|
| 32 |
$method = $this->getParameter('method', 'dsn'); |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
switch ($method) |
|---|
| 36 |
{ |
|---|
| 37 |
case 'dsn': |
|---|
| 38 |
$dsn = $this->getParameter('dsn'); |
|---|
| 39 |
|
|---|
| 40 |
if ($dsn == null) |
|---|
| 41 |
{ |
|---|
| 42 |
|
|---|
| 43 |
$error = 'Database configuration specifies method "dsn", but is missing dsn parameter'; |
|---|
| 44 |
|
|---|
| 45 |
throw new sfDatabaseException($error); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
break; |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
try |
|---|
| 52 |
{ |
|---|
| 53 |
$pdo_username = $this->getParameter('username'); |
|---|
| 54 |
$pdo_password = $this->getParameter('password'); |
|---|
| 55 |
|
|---|
| 56 |
$this->connection = new PDO($dsn, $pdo_username, $pdo_password); |
|---|
| 57 |
} |
|---|
| 58 |
catch (PDOException $e) |
|---|
| 59 |
{ |
|---|
| 60 |
throw new sfDatabaseException($e->getMessage()); |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
if (defined('PDO::ATTR_ERRMODE')) |
|---|
| 65 |
{ |
|---|
| 66 |
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|---|
| 67 |
} |
|---|
| 68 |
else |
|---|
| 69 |
{ |
|---|
| 70 |
$this->connection->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
* Executes the shutdown procedure. |
|---|
| 76 |
* |
|---|
| 77 |
* @return void |
|---|
| 78 |
* |
|---|
| 79 |
* @throws <b>sfDatabaseException</b> If an error occurs while shutting down this database |
|---|
| 80 |
*/ |
|---|
| 81 |
public function shutdown() |
|---|
| 82 |
{ |
|---|
| 83 |
if ($this->connection !== null) |
|---|
| 84 |
{ |
|---|
| 85 |
$this->connection = null; |
|---|
| 86 |
} |
|---|
| 87 |
} |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|