CI_DB_pdo_driver::db_connect PHP Method

db_connect() public method

Database connection
public db_connect ( boolean $persistent = FALSE ) : object
$persistent boolean
return object
    public function db_connect($persistent = FALSE)
    {
        $this->options[PDO::ATTR_PERSISTENT] = $persistent;
        try {
            return new PDO($this->dsn, $this->username, $this->password, $this->options);
        } catch (PDOException $e) {
            if ($this->db_debug && empty($this->failover)) {
                $this->display_error($e->getMessage(), '', TRUE);
            }
            return FALSE;
        }
    }

Usage Example

 /**
  * Non-persistent database connection
  *
  * @param	bool
  * @return	object
  */
 public function db_connect($persistent = FALSE)
 {
     /* Prior to PHP 5.3.6, even if the charset was supplied in the DSN
      * on connect - it was ignored. This is a work-around for the issue.
      *
      * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php
      */
     if (!is_php('5.3.6') && !empty($this->char_set)) {
         $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $this->char_set . (empty($this->dbcollat) ? '' : ' COLLATE ' . $this->dbcollat);
     }
     return parent::db_connect($persistent);
 }
All Usage Examples Of CI_DB_pdo_driver::db_connect