summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/pdo/pdo_driver.php
diff options
context:
space:
mode:
authorTimothy Warren <tim@timshomepage.net>2012-01-24 22:26:11 +0100
committerTimothy Warren <tim@timshomepage.net>2012-01-24 22:26:11 +0100
commitde15a0b7377db0ef3b1d43508401be3c2927c0ff (patch)
tree5d3f9fb534ca9fa17635ddcd8c3d38abe51deec2 /system/database/drivers/pdo/pdo_driver.php
parente943bc418b1a233fce98fa5ae80d0873e1e5245f (diff)
Revert "Cleaned up a few things in PDO driver"
Diffstat (limited to 'system/database/drivers/pdo/pdo_driver.php')
-rw-r--r--system/database/drivers/pdo/pdo_driver.php71
1 files changed, 32 insertions, 39 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 3d5412600..457cf714a 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -43,8 +43,6 @@
class CI_DB_pdo_driver extends CI_DB {
var $dbdriver = 'pdo';
- var $pdo_driver = '';
- var $dsn = '';
// the character used to excape - not necessary for PDO
var $_escape_char = '';
@@ -66,44 +64,39 @@ class CI_DB_pdo_driver extends CI_DB {
{
parent::__construct($params);
- $host = explode(":", $this->hostname);
- $this->pdo_driver = $host[0];
-
- $this->dsn = $this->hostname;
-
- switch($this->pdo_driver)
- {
- case "mysql":
- $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->dsn .= ";charset={$this->char_set}";
- }
-
- //Set the charset with the connection options
- $this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
- break;
-
- case "odbc":
- $this->_like_escape_str = " {escape '%s'} ";
- $this->_like_escape_chr = '!';
- break;
+ // clause and character used for LIKE escape sequences
+ if (strpos($this->hostname, 'mysql') !== FALSE)
+ {
+ $this->_like_escape_str = '';
+ $this->_like_escape_chr = '';
- case "sqlite":
-
- break;
+ //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}";
+ }
- default:
- $this->_like_escape_str = " ESCAPE '%s' ";
- $this->_like_escape_chr = '!';
- break;
+ //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)
+ {
+ $this->_like_escape_str = " {escape '%s'} ";
+ $this->_like_escape_chr = '!';
+ }
+ else
+ {
+ $this->_like_escape_str = " ESCAPE '%s' ";
+ $this->_like_escape_chr = '!';
+ }
+
+ if (strpos($this->hostname, 'sqlite') === FALSE)
+ {
+ $this->hostname .= ";dbname=".$this->database;
}
- $this->dsn .= ";dbname=".$this->database;
$this->trans_enabled = FALSE;
+
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
}
@@ -117,7 +110,7 @@ class CI_DB_pdo_driver extends CI_DB {
{
$this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
- return new PDO($this->dsn, $this->username, $this->password, $this->options);
+ return new PDO($this->hostname, $this->username, $this->password, $this->options);
}
// --------------------------------------------------------------------
@@ -133,7 +126,7 @@ class CI_DB_pdo_driver extends CI_DB {
$this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
$this->options['PDO::ATTR_PERSISTENT'] = TRUE;
- return new PDO($this->dsn, $this->username, $this->password, $this->options);
+ return new PDO($this->hostname, $this->username, $this->password, $this->options);
}
// --------------------------------------------------------------------
@@ -386,7 +379,7 @@ class CI_DB_pdo_driver extends CI_DB {
function insert_id($name=NULL)
{
//Convenience method for postgres insertid
- if ($this->pdo_driver === "pgsql")
+ if (strpos($this->hostname, 'pgsql') !== FALSE)
{
$v = $this->_version();
@@ -776,7 +769,7 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function _limit($sql, $limit, $offset)
{
- if ($this->pdo_driver === "cubrid" || $this->pdo_driver === "sqlite")
+ if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE)
{
if ($offset == 0)
{