Skip to content

Commit

Permalink
Initial steps toward getting complete query results in DboMysql using…
Browse files Browse the repository at this point in the history
… PDO
  • Loading branch information
lorenzo committed Oct 15, 2010
1 parent bd856c7 commit c54448d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions cake/libs/model/datasources/dbo/dbo_mysql.php
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -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']) {
Expand Down Expand Up @@ -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');
}

/**
Expand Down

0 comments on commit c54448d

Please sign in to comment.