summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/pdo
diff options
context:
space:
mode:
authorTimothy Warren <tim@timshomepage.net>2011-10-06 02:41:38 +0200
committerTimothy Warren <tim@timshomepage.net>2011-10-06 02:41:38 +0200
commitf7a8d86dbc6805a4e52964bbea76738df75b5f35 (patch)
treee243d089d272b8eea3c548d0c4b9e2d435c5c390 /system/database/drivers/pdo
parent47663970e357c51ad16d1a1a3d3b52428c022505 (diff)
Changed all db constructors to newer syntax, made insert_id() function more convenient for postgres on pdo driver
Diffstat (limited to 'system/database/drivers/pdo')
-rw-r--r--system/database/drivers/pdo/pdo_driver.php20
1 files changed, 19 insertions, 1 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 568819a08..1a84404bb 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -349,7 +349,25 @@ class CI_DB_pdo_driver extends CI_DB {
*/
function insert_id($name=NULL)
{
- return $this->conn_id->lastInsertId($name);
+ //Convenience method for postgres insertid
+ if(strpos($this->hostname, 'pgsql') !== FALSE)
+ {
+ $v = $this->_version();
+
+ $table = func_num_args() > 0 ? func_get_arg(0) : NULL;
+
+ if ($table == NULL && $v >= '8.1')
+ {
+ $sql='SELECT LASTVAL() as ins_id';
+ }
+ $query = $this->query($sql);
+ $row = $query->row();
+ return $row->ins_id;
+ }
+ else
+ {
+ return $this->conn_id->lastInsertId($name);
+ }
}
// --------------------------------------------------------------------