From 784ee985b5aa075a268bf66afaf40b2afdf4a8c8 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sat, 7 Apr 2007 01:42:12 +0000 Subject: [PATCH] Adding fix for Ticket #2363 Removed use of: mysql_insert_id($this->connection); mysqli_insert_id($this->connection); git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4810 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_mysql.php | 12 ++++-------- cake/libs/model/datasources/dbo/dbo_mysqli.php | 13 +++++-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 494440bd7..b4db3fba6 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -330,15 +330,11 @@ class DboMysql extends DboSource { * @return in */ function lastInsertId($source = null) { - $id = mysql_insert_id($this->connection); - if ($id) { - return $id; + $id = $this->fetchAll('SELECT LAST_INSERT_ID() AS insertID', false); + if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0][0]['insertID'])) { + return $id[0][0]['insertID']; } - $data = $this->fetchAll('SELECT LAST_INSERT_ID() as id From '.$source); - if ($data && isset($data[0]['id'])) { - return $data[0]['id']; - } return null; } /** @@ -569,4 +565,4 @@ class DboMysql extends DboSource { return $query; } } -?> \ No newline at end of file +?> diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index 8631aea84..fecc5939c 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -322,15 +322,12 @@ class DboMysqli extends DboSource { * @return in */ function lastInsertId($source = null) { - $id = mysqli_insert_id($this->connection); - if ($id) { - return $id; - } - - $data = $this->fetchAll('SELECT LAST_INSERT_ID() as id From '.$source); - if ($data && isset($data[0]['id'])) { - return $data[0]['id']; + $id = $this->fetchAll('SELECT LAST_INSERT_ID() AS insertID', false); + if ($id !== false && !empty($id) && !empty($id[0]) && isset($id[0][0]['insertID'])) { + return $id[0][0]['insertID']; } + + return null; } /** * Converts database-layer column types to basic types