[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * (c) 2004-2006 Sean Kerr. 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 /** 13 * sfPDODatabase provides connectivity for the PDO database abstraction layer. 14 * 15 * @package symfony 16 * @subpackage database 17 * @author Daniel Swarbrick (daniel@pressure.net.nz) 18 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 19 * @author Sean Kerr <skerr@mojavi.org> 20 * @version SVN: $Id: sfPDODatabase.class.php 3210 2007-01-10 20:28:16Z fabien $ 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 // determine how to get our parameters 32 $method = $this->getParameter('method', 'dsn'); 33 34 // get parameters 35 switch ($method) 36 { 37 case 'dsn': 38 $dsn = $this->getParameter('dsn'); 39 40 if ($dsn == null) 41 { 42 // missing required dsn parameter 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 // lets generate exceptions instead of silent failures 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 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |