summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/drivers/pdo/pdo_driver.php32
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 10 insertions, 23 deletions
diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php
index 44e93a042..dd803aba1 100644
--- a/system/database/drivers/pdo/pdo_driver.php
+++ b/system/database/drivers/pdo/pdo_driver.php
@@ -509,33 +509,19 @@ class CI_DB_pdo_driver extends CI_DB {
/**
* Insert ID
- *
- * @access public
- * @return integer
+ *
+ * @return int
*/
- function insert_id($name=NULL)
+ public function insert_id($name = NULL)
{
- if ($this->pdodriver == 'pgsql')
- {
- //Convenience method for postgres insertid
- $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
+ if ($this->pdodriver === 'pgsql' && $name === NULL && $this->_version() >= '8.1')
{
- return $this->conn_id->lastInsertId($name);
+ $query = $this->query('SELECT LASTVAL() AS ins_id');
+ $query = $query->row();
+ return $query->ins_id;
}
+
+ return $this->conn_id->lastInsertId($name);
}
// --------------------------------------------------------------------
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index b1bef0cd9..3d3c15897 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -119,6 +119,7 @@ Bug fixes for 3.0
- Fixed a bug (#611) - SQLSRV's _error_message() and _error_number() methods used to issue warnings when there's no actual error.
- Fixed a bug (#1036) - is_write_type() method in the :doc:`Database Library <database/index>` didn't return TRUE for RENAME and OPTIMIZE queries.
- Fixed a bug in PDO's _version() method where it used to return the client version as opposed to the server one.
+- Fixed a bug in PDO's insert_id() method where it could've failed if it's used with Postgre versions prior to 8.1.
Version 2.1.1
=============