CI_DB_pdo_driver::__construct PHP Method

__construct() public method

Validates the DSN string and/or detects the subdriver.
public __construct ( array $params ) : void
$params array
return void
    public function __construct($params)
    {
        parent::__construct($params);
        if (preg_match('/([^:]+):/', $this->dsn, $match) && count($match) === 2) {
            // If there is a minimum valid dsn string pattern found, we're done
            // This is for general PDO users, who tend to have a full DSN string.
            $this->subdriver = $match[1];
            return;
        } elseif (preg_match('/([^:]+):/', $this->hostname, $match) && count($match) === 2) {
            $this->dsn = $this->hostname;
            $this->hostname = NULL;
            $this->subdriver = $match[1];
            return;
        } elseif (in_array($this->subdriver, array('mssql', 'sybase'), TRUE)) {
            $this->subdriver = 'dblib';
        } elseif ($this->subdriver === '4D') {
            $this->subdriver = '4d';
        } elseif (!in_array($this->subdriver, array('4d', 'cubrid', 'dblib', 'firebird', 'ibm', 'informix', 'mysql', 'oci', 'odbc', 'pgsql', 'sqlite', 'sqlsrv'), TRUE)) {
            log_message('error', 'PDO: Invalid or non-existent subdriver');
            if ($this->db_debug) {
                show_error('Invalid or non-existent PDO subdriver');
            }
        }
        $this->dsn = NULL;
    }

Usage Example

 /**
  * Constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'sqlsrv:Server=' . (empty($this->hostname) ? '127.0.0.1' : $this->hostname);
         empty($this->port) or $this->dsn .= ',' . $this->port;
         empty($this->database) or $this->dsn .= ';Database=' . $this->database;
         // Some custom options
         if (isset($this->QuotedId)) {
             $this->dsn .= ';QuotedId=' . $this->QuotedId;
             $this->_quoted_identifier = (bool) $this->QuotedId;
         }
         if (isset($this->ConnectionPooling)) {
             $this->dsn .= ';ConnectionPooling=' . $this->ConnectionPooling;
         }
         if (isset($this->Encrypt)) {
             $this->dsn .= ';Encrypt=' . $this->Encrypt;
         }
         if (isset($this->TraceOn)) {
             $this->dsn .= ';TraceOn=' . $this->TraceOn;
         }
         if (isset($this->TrustServerCertificate)) {
             $this->dsn .= ';TrustServerCertificate=' . $this->TrustServerCertificate;
         }
         empty($this->APP) or $this->dsn .= ';APP=' . $this->APP;
         empty($this->Failover_Partner) or $this->dsn .= ';Failover_Partner=' . $this->Failover_Partner;
         empty($this->LoginTimeout) or $this->dsn .= ';LoginTimeout=' . $this->LoginTimeout;
         empty($this->MultipleActiveResultSets) or $this->dsn .= ';MultipleActiveResultSets=' . $this->MultipleActiveResultSets;
         empty($this->TraceFile) or $this->dsn .= ';TraceFile=' . $this->TraceFile;
         empty($this->WSID) or $this->dsn .= ';WSID=' . $this->WSID;
     } elseif (preg_match('/QuotedId=(0|1)/', $this->dsn, $match)) {
         $this->_quoted_identifier = (bool) $match[1];
     }
 }
All Usage Examples Of CI_DB_pdo_driver::__construct