Development

Changeset 8249

You must first sign up to be able to contribute.

Changeset 8249

Show
Ignore:
Timestamp:
04/03/08 23:18:59 (1 year ago)
Author:
dwhittle
Message:

1.1: added options to sfPDODatabase (persistent, nulls, autocommit)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/database/sfPDODatabase.class.php

    r7792 r8249  
    55 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 
    66 * (c) 2004-2006 Sean Kerr <sean@code-box.org> 
    7  *  
     7 * 
    88 * For the full copyright and license information, please view the LICENSE 
    99 * file that was distributed with this source code. 
     
    1818 * @author     Fabien Potencier <fabien.potencier@symfony-project.com> 
    1919 * @author     Sean Kerr <sean@code-box.org> 
     20 * @author     Dustin Whittle <dustin.whittle@symfony-project.com> 
    2021 * @version    SVN: $Id$ 
    2122 */ 
     
    3637    { 
    3738      case 'dsn': 
     39 
    3840        $dsn = $this->getParameter('dsn'); 
    3941 
     
    4951    try 
    5052    { 
    51       $pdo_username = $this->getParameter('username'); 
    52       $pdo_password = $this->getParameter('password'); 
    53       $pdo_class    = $this->getParameter('class', 'PDO'); 
     53      $pdo_class  = $this->getParameter('class', 'PDO'); 
     54      $username   = $this->getParameter('username'); 
     55      $password   = $this->getParameter('password'); 
     56      $persistent = $this->getParameter('persistent'); 
    5457 
    55       $this->connection = new $pdo_class($dsn, $pdo_username, $pdo_password); 
     58      $options = ($persistent) ? array(PDO::ATTR_PERSISTENT => true) : array(PDO::ATTR_PERSISTENT => false); 
     59 
     60      $this->connection = new $pdo_class($dsn, $username, $password, $options); 
     61 
    5662    } 
    5763    catch (PDOException $e) 
     
    6167 
    6268    // lets generate exceptions instead of silent failures 
    63     if (defined('PDO::ATTR_ERRMODE')) 
     69    if(sfConfig::get('sf_debug')) 
    6470    { 
    6571      $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     
    6773    else 
    6874    { 
    69       $this->connection->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION); 
     75      $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); 
     76    } 
     77 
     78    // compatability 
     79    $compatability = $this->getParameter('compat'); 
     80    if($compatability) 
     81    { 
     82      $this->connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); 
     83    } 
     84 
     85    // nulls 
     86    $nulls = $this->getParameter('nulls'); 
     87    if($nulls) 
     88    { 
     89      $this->connection->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING); 
     90    } 
     91 
     92    // auto commit 
     93    $autocommit = $this->getParameter('autocommit'); 
     94    if($autocommit) 
     95    { 
     96      $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, true); 
    7097    } 
    7198 
    7299    $this->resource = $this->connection; 
     100 
    73101  } 
    74102 
    75103  /** 
    76    * Executes the shutdown procedure. 
     104   * Execute the shutdown procedure. 
    77105   * 
    78106   * @return void 
     107   */ 
     108  public function shutdown () 
     109  { 
     110    if ($this->connection !== null) 
     111    { 
     112      @$this->connection = null; 
     113    } 
     114  } 
     115 
     116  /** 
     117   * Magic method for calling PDO directly via sfPDODatabase 
    79118   * 
    80    * @throws <b>sfDatabaseException</b> If an error occurs while shutting down this database 
     119   * @param string $method 
     120   * @param array $arguments 
     121   * @return mixed 
    81122   */ 
    82   public function shutdown(
     123  public function __call($method, $arguments
    83124  { 
    84     $this->connection = null
     125    return $this->getConnection()->$method($arguments)
    85126  } 
    86127} 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.