summaryrefslogtreecommitdiffstats
path: root/system/database/drivers
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-10-31 17:32:19 +0100
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-10-31 17:32:19 +0100
commit3485f7e2f14a7f96e348d3c927ee256c8d290027 (patch)
tree121a6c3f6582324673d9c8bd1d07f6185cde4746 /system/database/drivers
parent308692d1fad226e98482797fb3feed7a1b42601e (diff)
parentd93393f446c59707f655407594ff0fe307c1b9d6 (diff)
Merge pull request #606 from timw4mail/develop
PDO/MySQL charset setting fix.
Diffstat (limited to 'system/database/drivers')
-rw-r--r--system/database/drivers/pdo/pdo_driver.php29
1 files changed, 20 insertions, 9 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 10ef00c49..a66a16e90 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -57,7 +57,8 @@ class CI_DB_pdo_driver extends CI_DB {
*/
var $_count_string = "SELECT COUNT(*) AS ";
var $_random_keyword;
-
+
+ var $options = array();
function __construct($params)
{
@@ -68,6 +69,15 @@ class CI_DB_pdo_driver extends CI_DB {
{
$this->_like_escape_str = '';
$this->_like_escape_chr = '';
+
+ //Prior to this version, the charset can't be set in the dsn
+ if(is_php('5.3.6'))
+ {
+ $this->hostname .= ";charset={$this->char_set}";
+ }
+
+ //Set the charset with the connection options
+ $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
}
else if (strpos($this->hostname, 'odbc') !== FALSE)
{
@@ -80,7 +90,8 @@ class CI_DB_pdo_driver extends CI_DB {
$this->_like_escape_chr = '!';
}
- $this->hostname = $this->hostname . ";dbname=".$this->database;
+ $this->hostname .= ";dbname=".$this->database;
+
$this->trans_enabled = FALSE;
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
@@ -94,9 +105,9 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function db_connect()
{
- return new PDO($this->hostname,$this->username,$this->password, array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT
- ));
+ $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
+
+ return new PDO($this->hostname, $this->username, $this->password, $this->options);
}
// --------------------------------------------------------------------
@@ -109,10 +120,10 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function db_pconnect()
{
- return new PDO($this->hostname,$this->username,$this->password, array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT,
- PDO::ATTR_PERSISTENT => true
- ));
+ $this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
+ $this->options['PDO::ATTR_PERSISTENT'] = TRUE;
+
+ return new PDO($this->hostname, $this->username, $this->password, $this->options);
}
// --------------------------------------------------------------------