Note: _DB is an extender class that the app controller creates dynamically based on whether the active record class is being used or not.
Author: EllisLab Dev Team
Inheritance: extends CI_DB
 /**
  * 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 = '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';
     }
 }
 /**
  * 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 = 'odbc:';
         // 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;
         }
         // If the DSN is not pre-configured - try to build an IBM DB2 connection string
         $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;');
     }
 }
 /**
  * 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 = '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;
     }
 }
Example #4
0
 /**
  * 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 = '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;
     }
 }
 /**
  * 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);
 }
 /**
  * Non-persistent database connection
  *
  * @param	bool
  * @return	object
  */
 public function db_connect($persistent = FALSE)
 {
     $this->conn_id = parent::db_connect($persistent);
     if (!is_object($this->conn_id)) {
         return $this->conn_id;
     }
     // Determine how identifiers are escaped
     $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
     $query = $query->row_array();
     $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
     $this->_escape_char = $this->_quoted_identifier ? '"' : array('[', ']');
     return $this->conn_id;
 }
 /**
  * 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 = '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;
     }
 }
 /**
  * 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 = '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;
     }
 }
 /**
  * Delete statement
  *
  * Generates a platform-specific delete string from the supplied data
  *
  * @param	string	$table
  * @return	string
  */
 protected function _delete($table)
 {
     $this->qb_limit = FALSE;
     return parent::_delete($table);
 }
 /**
  * Non-persistent database connection
  *
  * @param	bool
  * @return	object
  */
 public function db_connect($persistent = FALSE)
 {
     if (!empty($this->char_set) && preg_match('/utf[^8]*8/i', $this->char_set)) {
         $this->options[PDO::SQLSRV_ENCODING_UTF8] = 1;
     }
     $this->conn_id = parent::db_connect($persistent);
     if (!is_object($this->conn_id) or is_bool($this->_quoted_identifier)) {
         return $this->conn_id;
     }
     // Determine how identifiers are escaped
     $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
     $query = $query->row_array();
     $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
     $this->_escape_char = $this->_quoted_identifier ? '"' : array('[', ']');
     return $this->conn_id;
 }
Example #11
0
 /**
  * Database connection
  *
  * @param	bool	$persistent
  * @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);
     }
     if ($this->stricton) {
         if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND])) {
             $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode="STRICT_ALL_TABLES"';
         } else {
             $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = "STRICT_ALL_TABLES"';
         }
     }
     if ($this->compress === TRUE) {
         $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE;
     }
     // SSL support was added to PDO_MYSQL in PHP 5.3.7
     if (is_array($this->encrypt) && is_php('5.3.7')) {
         $ssl = array();
         empty($this->encrypt['ssl_key']) or $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key'];
         empty($this->encrypt['ssl_cert']) or $ssl[PDO::MYSQL_ATTR_SSL_CERT] = $this->encrypt['ssl_cert'];
         empty($this->encrypt['ssl_ca']) or $ssl[PDO::MYSQL_ATTR_SSL_CA] = $this->encrypt['ssl_ca'];
         empty($this->encrypt['ssl_capath']) or $ssl[PDO::MYSQL_ATTR_SSL_CAPATH] = $this->encrypt['ssl_capath'];
         empty($this->encrypt['ssl_cipher']) or $ssl[PDO::MYSQL_ATTR_SSL_CIPHER] = $this->encrypt['ssl_cipher'];
         // DO NOT use array_merge() here!
         // It re-indexes numeric keys and the PDO_MYSQL_ATTR_SSL_* constants are integers.
         empty($ssl) or $this->options += $ssl;
     }
     // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
     if (($pdo = parent::db_connect($persistent)) !== FALSE && !empty($ssl) && version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '5.7.3', '<=') && empty($pdo->query("SHOW STATUS LIKE 'ssl_cipher'")->fetchObject()->Value)) {
         $message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!';
         log_message('error', $message);
         return $this->db->db_debug ? $this->db->display_error($message, '', TRUE) : FALSE;
     }
     return $pdo;
 }
Example #12
0
 /**
  * Insert batch statement
  *
  * Generates a platform-specific insert string from the supplied data.
  *
  * @param    string $table Table name
  * @param    array $keys INSERT keys
  * @param    array $values INSERT values
  * @return    string|bool
  */
 protected function _insert_batch($table, $keys, $values)
 {
     // Multiple-value inserts are only supported as of SQL Server 2008
     if (version_compare($this->version(), '10', '>=')) {
         return parent::_insert_batch($table, $keys, $values);
     }
     return $this->db->db_debug ? $this->db->display_error('db_unsupported_feature') : FALSE;
 }
Example #13
0
 /**
  * Delete statement
  *
  * Generates a platform-specific delete string from the supplied data
  *
  * @param	string	$table
  * @return	string
  */
 protected function _delete($table)
 {
     if ($this->qb_limit) {
         $this->where('rownum <= ', $this->qb_limit, FALSE);
         $this->qb_limit = FALSE;
     }
     return parent::_delete($table);
 }
 /**
  * Database connection
  *
  * @param	bool	$persistent
  * @return	object
  * @todo	SSL support
  */
 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);
     }
     if ($this->stricton) {
         if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND])) {
             $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode="STRICT_ALL_TABLES"';
         } else {
             $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = "STRICT_ALL_TABLES"';
         }
     }
     if ($this->compress === TRUE) {
         $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE;
     }
     return parent::db_connect($persistent);
 }
 /**
  * Replace statement
  *
  * @param	string	$table	Table name
  * @param	array	$keys	INSERT keys
  * @param	array	$values	INSERT values
  * @return 	string
  */
 protected function _replace($table, $keys, $values)
 {
     return 'INSERT OR ' . parent::_replace($table, $keys, $values);
 }
 /**
  * Database connection
  *
  * @param	bool	$persistent
  * @return	object
  */
 public function db_connect($persistent = FALSE)
 {
     if (isset($this->stricton)) {
         if ($this->stricton) {
             $sql = 'CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")';
         } else {
             $sql = 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                                     @@sql_mode,
                                     "STRICT_ALL_TABLES,", ""),
                                     ",STRICT_ALL_TABLES", ""),
                                     "STRICT_ALL_TABLES", ""),
                                     "STRICT_TRANS_TABLES,", ""),
                                     ",STRICT_TRANS_TABLES", ""),
                                     "STRICT_TRANS_TABLES", "")';
         }
         if (!empty($sql)) {
             if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND])) {
                 $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode = ' . $sql;
             } else {
                 $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = ' . $sql;
             }
         }
     }
     if ($this->compress === TRUE) {
         $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE;
     }
     if (is_array($this->encrypt)) {
         $ssl = array();
         empty($this->encrypt['ssl_key']) or $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key'];
         empty($this->encrypt['ssl_cert']) or $ssl[PDO::MYSQL_ATTR_SSL_CERT] = $this->encrypt['ssl_cert'];
         empty($this->encrypt['ssl_ca']) or $ssl[PDO::MYSQL_ATTR_SSL_CA] = $this->encrypt['ssl_ca'];
         empty($this->encrypt['ssl_capath']) or $ssl[PDO::MYSQL_ATTR_SSL_CAPATH] = $this->encrypt['ssl_capath'];
         empty($this->encrypt['ssl_cipher']) or $ssl[PDO::MYSQL_ATTR_SSL_CIPHER] = $this->encrypt['ssl_cipher'];
         // DO NOT use array_merge() here!
         // It re-indexes numeric keys and the PDO_MYSQL_ATTR_SSL_* constants are integers.
         empty($ssl) or $this->options += $ssl;
     }
     // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
     if (($pdo = parent::db_connect($persistent)) !== FALSE && !empty($ssl) && version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '5.7.3', '<=') && empty($pdo->query("SHOW STATUS LIKE 'ssl_cipher'")->fetchObject()->Value)) {
         $message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!';
         log_message('error', $message);
         return $this->db->db_debug ? $this->db->display_error($message, '', TRUE) : FALSE;
     }
     return $pdo;
 }
Example #17
0
 /**
  * Database version number
  *
  * @return    string
  */
 public function version()
 {
     if (isset($this->data_cache['version'])) {
         return $this->data_cache['version'];
     }
     $version_string = parent::version();
     if (preg_match('#Release\\s(?<version>\\d+(?:\\.\\d+)+)#', $version_string, $match)) {
         return $this->data_cache['version'] = $match[1];
     }
     return FALSE;
 }
Example #18
0
 /**
  * Delete statement
  *
  * Generates a platform-specific delete string from the supplied data
  *
  * @param	string	the table name
  * @return	string
  */
 protected function _delete($table)
 {
     if ($this->qb_limit) {
         return 'WITH ci_delete AS (SELECT TOP ' . $this->qb_limit . ' * FROM ' . $table . $this->_compile_wh('qb_where') . ') DELETE FROM ci_delete';
     }
     return parent::_delete($table);
 }
Example #19
0
 /**
  * Determines if a query is a "write" type.
  *
  * @param	string	An SQL query string
  * @return	bool
  */
 public function is_write_type($sql)
 {
     if (preg_match('#^(INSERT|UPDATE).*RETURNING\\s.+(\\,\\s?.+)*$#i', $sql)) {
         return FALSE;
     }
     return parent::is_write_type($sql);
 }
Example #20
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();
 }
Example #21
0
 /**
  * Database connection
  *
  * @param	bool	$persistent
  * @return	object
  */
 public function db_connect($persistent = FALSE)
 {
     if (isset($this->stricton)) {
         if ($this->stricton) {
             $sql = 'CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")';
         } else {
             $sql = 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
                                     @@sql_mode,
                                     "STRICT_ALL_TABLES,", ""),
                                     ",STRICT_ALL_TABLES", ""),
                                     "STRICT_ALL_TABLES", ""),
                                     "STRICT_TRANS_TABLES,", ""),
                                     ",STRICT_TRANS_TABLES", ""),
                                     "STRICT_TRANS_TABLES", "")';
         }
         if (!empty($sql)) {
             if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND])) {
                 $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode = ' . $sql;
             } else {
                 $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = ' . $sql;
             }
         }
     }
     return parent::db_connect($persistent);
 }