diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 707d0cbeb..75eb18e80 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -267,17 +267,15 @@ class DboMysql extends DboSource { /** * Returns a formatted error message from previous database operation. * + * @param PDOStatement $query the query to extract the error from if any * @return string Error message with error number */ - function lastError() { - if ($this->hasResult()) { - $error = $this->_result->errorInfo(); - if (empty($error)) { - $error; - } - return $error[1] . ': ' . $error[2]; + function lastError(PDOStatement $query = null) { + $error = $query->errorInfo(); + if (empty($error[2])) { + return null; } - return null; + return $error[1] . ': ' . $error[2]; } /** diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index de060fb44..cb64234c3 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -242,6 +242,7 @@ class DboSource extends DataSource { public function execute($sql, $options = array(), $params = array()) { $defaults = array('stats' => true, 'log' => $this->fullDebug); $options = array_merge($defaults, $options); + $this->error = null; $t = microtime(true); $this->_result = $this->_execute($sql, $params); @@ -274,7 +275,8 @@ class DboSource extends DataSource { $query = $this->_connection->prepare($sql); $query->setFetchMode(PDO::FETCH_LAZY); if (!$query->execute($params)) { - $this->error = $this->lastError(); + $this->_results = $query; + $this->error = $this->lastError($query); return false; } if (!$query->columnCount()) {