Skip to content
Permalink
Browse files

Initial steps toward getting complete query results in DboMysql using…

… PDO
  • Loading branch information...
lorenzo committed Oct 15, 2010
1 parent bd856c7 commit c54448d20530ffe329e3bd788128ee0d41c4d3fd
Showing with 13 additions and 9 deletions.
  1. +8 −4 cake/libs/model/datasources/dbo/dbo_mysql.php
  2. +5 −5 cake/libs/model/datasources/dbo_source.php
@@ -695,8 +695,12 @@ function value($data, $column = null, $safe = false) {
* @return string Error message with error number
*/
function lastError() {
if (mysql_errno($this->connection)) {
return mysql_errno($this->connection).': '.mysql_error($this->connection);
if ($this->hasResult()) {
$error = $this->_result->errorInfo();
if (empty($error)) {
$error;
}
return $error[1] . ': ' . $error[2];
}
return null;
}
@@ -708,8 +712,8 @@ function lastError() {
* @return integer Number of affected rows
*/
function lastAffected() {
if ($this->_result) {
return mysql_affected_rows($this->connection);
if ($this->hasResult()) {
return $this->_result->rowCount();
}
return null;
}
@@ -235,20 +235,20 @@ public function rawQuery($sql, $params = array()) {
* - log - Whether or not the query should be logged to the memory log.
*
* @param string $sql
* @param array $params values to be bided to the query
* @param array $options
* @return mixed Resource or object representing the result set, or false on failure
*/
public function execute($sql, $options = array()) {
public function execute($sql, $params = array(), $options = array()) {
$defaults = array('stats' => true, 'log' => $this->fullDebug);
$options = array_merge($defaults, $options);
$t = microtime(true);
$this->_result = $this->_execute($sql);
$this->_result = $this->_execute($sql, $params);
if ($options['stats']) {
$this->took = round((microtime(true) - $t) * 1000, 0);
$this->affected = $this->lastAffected();
$this->error = $this->lastError();
$this->numRows = $this->lastNumRows();
//$this->numRows = $this->lastNumRows();
}
if ($options['log']) {
@@ -576,7 +576,7 @@ public function isConnected() {
* @return boolean True if the result is valid else false
*/
public function hasResult() {
return is_resource($this->_result);
return is_a($this->_result, 'PDOStatement');
}
/**

0 comments on commit c54448d

Please sign in to comment.
You can’t perform that action at this time.