__construct() public method

Validates the DSN string and/or detects the subdriver.
public __construct ( array $params ) : void
$params array
return void
 /**
  * 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];
     }
 }
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'informix:';
         // Pre-defined DSN
         if (empty($this->hostname) && empty($this->host) && empty($this->port) && empty($this->service)) {
             if (isset($this->DSN)) {
                 $this->dsn .= 'DSN=' . $this->DSN;
             } elseif (!empty($this->database)) {
                 $this->dsn .= 'DSN=' . $this->database;
             }
             return;
         }
         if (isset($this->host)) {
             $this->dsn .= 'host=' . $this->host;
         } else {
             $this->dsn .= 'host=' . (empty($this->hostname) ? '127.0.0.1' : $this->hostname);
         }
         if (isset($this->service)) {
             $this->dsn .= '; service=' . $this->service;
         } elseif (!empty($this->port)) {
             $this->dsn .= '; service=' . $this->port;
         }
         empty($this->database) or $this->dsn .= '; database=' . $this->database;
         empty($this->server) or $this->dsn .= '; server=' . $this->server;
         $this->dsn .= '; protocol=' . (isset($this->protocol) ? $this->protocol : 'onsoctcp') . '; EnableScrollableCursors=1';
     }
 }
示例#3
0
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'ibm:';
         // Pre-defined DSN
         if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT)) {
             if (isset($this->DSN)) {
                 $this->dsn .= 'DSN=' . $this->DSN;
             } elseif (!empty($this->database)) {
                 $this->dsn .= 'DSN=' . $this->database;
             }
             return;
         }
         $this->dsn .= 'DRIVER=' . (isset($this->DRIVER) ? '{' . $this->DRIVER . '}' : '{IBM DB2 ODBC DRIVER}') . ';';
         if (isset($this->DATABASE)) {
             $this->dsn .= 'DATABASE=' . $this->DATABASE . ';';
         } elseif (!empty($this->database)) {
             $this->dsn .= 'DATABASE=' . $this->database . ';';
         }
         if (isset($this->HOSTNAME)) {
             $this->dsn .= 'HOSTNAME=' . $this->HOSTNAME . ';';
         } else {
             $this->dsn .= 'HOSTNAME=' . (empty($this->hostname) ? '127.0.0.1;' : $this->hostname . ';');
         }
         if (isset($this->PORT)) {
             $this->dsn .= 'PORT=' . $this->port . ';';
         } elseif (!empty($this->port)) {
             $this->dsn .= ';PORT=' . $this->port . ';';
         }
         $this->dsn .= 'PROTOCOL=' . (isset($this->PROTOCOL) ? $this->PROTOCOL . ';' : 'TCPIP;');
     }
 }
示例#4
0
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'pgsql:host=' . (empty($this->hostname) ? '127.0.0.1' : $this->hostname);
         empty($this->port) or $this->dsn .= ';port=' . $this->port;
         empty($this->database) or $this->dsn .= ';dbname=' . $this->database;
     }
 }
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'sqlite:';
         if (empty($this->database) && empty($this->hostname)) {
             $this->database = ':memory:';
         }
         $this->database = empty($this->database) ? $this->hostname : $this->database;
     }
 }
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = '4D:host=' . (empty($this->hostname) ? '127.0.0.1' : $this->hostname);
         empty($this->port) or $this->dsn .= ';port=' . $this->port;
         empty($this->database) or $this->dsn .= ';dbname=' . $this->database;
         empty($this->char_set) or $this->dsn .= ';charset=' . $this->char_set;
     } elseif (!empty($this->char_set) && strpos($this->dsn, 'charset=', 3) === FALSE) {
         $this->dsn .= ';charset=' . $this->char_set;
     }
 }
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'firebird:';
         if (!empty($this->database)) {
             $this->dsn .= 'dbname=' . $this->database;
         } elseif (!empty($this->hostname)) {
             $this->dsn .= 'dbname=' . $this->hostname;
         }
         empty($this->char_set) or $this->dsn .= ';charset=' . $this->char_set;
         empty($this->role) or $this->dsn .= ';role=' . $this->role;
     } elseif (!empty($this->char_set) && strpos($this->dsn, 'charset=', 9) === FALSE) {
         $this->dsn .= ';charset=' . $this->char_set;
     }
 }
示例#8
0
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param    array $params
  * @return    void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = $params['subdriver'] . ':host=' . (empty($this->hostname) ? '127.0.0.1' : $this->hostname);
         if (!empty($this->port)) {
             $this->dsn .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':') . $this->port;
         }
         empty($this->database) or $this->dsn .= ';dbname=' . $this->database;
         empty($this->char_set) or $this->dsn .= ';charset=' . $this->char_set;
         empty($this->appname) or $this->dsn .= ';appname=' . $this->appname;
     } else {
         if (!empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE) {
             $this->dsn .= ';charset=' . $this->char_set;
         }
         $this->subdriver = 'dblib';
     }
 }
示例#9
0
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param    array $params
  * @return    void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'oci:dbname=';
         // Oracle has a slightly different PDO DSN format (Easy Connect),
         // which also supports pre-defined DSNs.
         if (empty($this->hostname) && empty($this->port)) {
             $this->dsn .= $this->database;
         } else {
             $this->dsn .= '//' . (empty($this->hostname) ? '127.0.0.1' : $this->hostname) . (empty($this->port) ? '' : ':' . $this->port) . '/';
             empty($this->database) or $this->dsn .= $this->database;
         }
         empty($this->char_set) or $this->dsn .= ';charset=' . $this->char_set;
     } elseif (!empty($this->char_set) && strpos($this->dsn, 'charset=', 4) === FALSE) {
         $this->dsn .= ';charset=' . $this->char_set;
     }
 }
示例#10
0
 /**
  * Class constructor
  *
  * Builds the DSN if not already set.
  *
  * @param	array	$params
  * @return	void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     $this->_build_dsn();
 }
示例#11
0
 /**
  * Class constructor.
  *
  * Builds the DSN if not already set.
  *
  * @param array $params
  *
  * @return void
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($this->dsn)) {
         $this->dsn = 'mysql:host=' . (empty($this->hostname) ? '127.0.0.1' : $this->hostname);
         empty($this->port) or $this->dsn .= ';port=' . $this->port;
         empty($this->database) or $this->dsn .= ';dbname=' . $this->database;
         empty($this->char_set) or $this->dsn .= ';charset=' . $this->char_set;
     } elseif (!empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === false && is_php('5.3.6')) {
         $this->dsn .= ';charset=' . $this->char_set;
     }
 }