summaryrefslogtreecommitdiffstats
path: root/system/database
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-10-12 19:51:39 +0200
committerAndrey Andreev <narf@bofh.bg>2012-10-12 19:51:39 +0200
commitf83c4363b5459d294255e3817a230258861ec79b (patch)
treee88929ac21246cab365d865ccc82aed56663a414 /system/database
parenta23e10fd2369cc85c4b942c5de6a8cf05a5b2b67 (diff)
parent98ebf4351f8aad58504cd7318ddd94faf0dec482 (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into feature/db_qb_aliasing
Diffstat (limited to 'system/database')
-rw-r--r--system/database/DB_driver.php2
-rw-r--r--system/database/drivers/mysql/mysql_driver.php27
-rw-r--r--system/database/drivers/mysqli/mysqli_driver.php49
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php7
-rw-r--r--system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php4
-rw-r--r--system/database/drivers/sqlsrv/sqlsrv_driver.php9
6 files changed, 41 insertions, 57 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 02c64f9f1..b7b19d207 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -51,7 +51,7 @@ abstract class CI_DB_driver {
public $char_set = 'utf8';
public $dbcollat = 'utf8_general_ci';
public $autoinit = TRUE; // Whether to automatically initialize the DB
- public $compress = TRUE;
+ public $encrypt = FALSE;
public $swap_pre = '';
public $port = '';
public $pconnect = FALSE;
diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php
index 60bcf3cfc..ce9f73011 100644
--- a/system/database/drivers/mysql/mysql_driver.php
+++ b/system/database/drivers/mysql/mysql_driver.php
@@ -41,6 +41,7 @@
class CI_DB_mysql_driver extends CI_DB {
public $dbdriver = 'mysql';
+ public $compress = FALSE;
// The character used for escaping
protected $_escape_char = '`';
@@ -75,18 +76,21 @@ class CI_DB_mysql_driver extends CI_DB {
/**
* Non-persistent database connection
*
+ * @param bool
* @return resource
*/
- public function db_connect()
+ public function db_connect($persistent = FALSE)
{
- if ($this->compress === TRUE)
- {
- return @mysql_connect($this->hostname, $this->username, $this->password, TRUE, MYSQL_CLIENT_COMPRESS);
- }
- else
+ $client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS;
+
+ if ($this->encrypt === TRUE)
{
- return @mysql_connect($this->hostname, $this->username, $this->password, TRUE);
+ $client_flags = $client_flags | MYSQL_CLIENT_SSL;
}
+
+ return ($persistent === TRUE)
+ ? @mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags)
+ : @mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags);
}
// --------------------------------------------------------------------
@@ -98,14 +102,7 @@ class CI_DB_mysql_driver extends CI_DB {
*/
public function db_pconnect()
{
- if ($this->compress === TRUE)
- {
- return @mysql_pconnect($this->hostname, $this->username, $this->password, MYSQL_CLIENT_COMPRESS);
- }
- else
- {
- return @mysql_pconnect($this->hostname, $this->username, $this->password);
- }
+ return $this->db_connect(TRUE);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php
index 934694c6c..0a454da6c 100644
--- a/system/database/drivers/mysqli/mysqli_driver.php
+++ b/system/database/drivers/mysqli/mysqli_driver.php
@@ -41,6 +41,7 @@
class CI_DB_mysqli_driver extends CI_DB {
public $dbdriver = 'mysqli';
+ public $compress = FALSE;
// The character used for escaping
protected $_escape_char = '`';
@@ -57,24 +58,21 @@ class CI_DB_mysqli_driver extends CI_DB {
/**
* Non-persistent database connection
*
+ * @param bool
* @return object
+ * @todo SSL support
*/
- public function db_connect()
+ public function db_connect($persistent = FALSE)
{
- // Use MySQL client compression?
- if ($this->compress === TRUE)
- {
- $port = empty($this->port) ? NULL : $this->port;
-
- $mysqli = new mysqli();
- @$mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS);
-
- return $mysqli;
- }
-
- return empty($this->port)
- ? @new mysqli($this->hostname, $this->username, $this->password, $this->database)
- : @new mysqli($this->hostname, $this->username, $this->password, $this->database, $this->port);
+ // Persistent connection support was added in PHP 5.3.0
+ $hostname = ($persistent === TRUE && is_php('5.3'))
+ ? 'p:'.$this->hostname : $this->hostname;
+ $port = empty($this->port) ? NULL : $this->port;
+ $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0;
+ $mysqli = new mysqli();
+
+ return @$mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, NULL, $client_flags)
+ ? $mysqli : FALSE;
}
// --------------------------------------------------------------------
@@ -86,26 +84,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
public function db_pconnect()
{
- // Persistent connection support was added in PHP 5.3.0
- if ( ! is_php('5.3'))
- {
- return $this->db_connect();
- }
-
- // Use MySQL client compression?
- if ($this->compress === TRUE)
- {
- $port = empty($this->port) ? NULL : $this->port;
-
- $mysqli = mysqli_init();
- $mysqli->real_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS);
-
- return $mysqli;
- }
-
- return empty($this->port)
- ? @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database)
- : @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port);
+ return $this->db_connect(TRUE);
}
// --------------------------------------------------------------------
diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
index 9ffb93eed..0fb5d8f12 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php
@@ -41,6 +41,7 @@
class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
public $subdriver = 'mysql';
+ public $compress = FALSE;
protected $_escape_char = '`';
@@ -79,6 +80,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
*
* @param bool
* @return object
+ * @todo SSL support
*/
public function db_connect($persistent = FALSE)
{
@@ -93,6 +95,11 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver {
.(empty($this->dbcollat) ? '' : ' COLLATE '.$this->dbcollat);
}
+ if ($this->compress === TRUE)
+ {
+ $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE;
+ }
+
return parent::db_connect($persistent);
}
diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
index 5b1cd9789..64be355f8 100644
--- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
+++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php
@@ -78,9 +78,9 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver {
$this->dsn .= ';ConnectionPooling='.$this->ConnectionPooling;
}
- if (isset($this->Encrypt))
+ if ($this->encrypt === TRUE)
{
- $this->dsn .= ';Encrypt='.$this->Encrypt;
+ $this->dsn .= ';Encrypt=1';
}
if (isset($this->TraceOn))
diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php
index 659429256..31a0d9d10 100644
--- a/system/database/drivers/sqlsrv/sqlsrv_driver.php
+++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php
@@ -57,15 +57,16 @@ class CI_DB_sqlsrv_driver extends CI_DB {
*/
public function db_connect($pooling = FALSE)
{
- // Check for a UTF-8 charset being passed as CI's default 'utf8'.
- $character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set;
+ $charset = in_array(strtolower($this->char_set), array('utf-8', 'utf8'), TRUE)
+ ? 'UTF-8' : SQLSRV_ENC_CHAR;
$connection = array(
'UID' => empty($this->username) ? '' : $this->username,
'PWD' => empty($this->password) ? '' : $this->password,
'Database' => $this->database,
- 'ConnectionPooling' => $pooling ? 1 : 0,
- 'CharacterSet' => $character_set,
+ 'ConnectionPooling' => ($pooling === TRUE) ? 1 : 0,
+ 'CharacterSet' => $charset,
+ 'Encrypt' => ($this->encrypt === TRUE) ? 1 : 0,
'ReturnDatesAsStrings' => 1
);