mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Initial steps toward getting complete query results in DboMysql using PDO
This commit is contained in:
parent
bd856c7ef9
commit
c54448d205
2 changed files with 13 additions and 9 deletions
|
@ -695,8 +695,12 @@ class DboMysql extends DboMysqlBase {
|
||||||
* @return string Error message with error number
|
* @return string Error message with error number
|
||||||
*/
|
*/
|
||||||
function lastError() {
|
function lastError() {
|
||||||
if (mysql_errno($this->connection)) {
|
if ($this->hasResult()) {
|
||||||
return mysql_errno($this->connection).': '.mysql_error($this->connection);
|
$error = $this->_result->errorInfo();
|
||||||
|
if (empty($error)) {
|
||||||
|
$error;
|
||||||
|
}
|
||||||
|
return $error[1] . ': ' . $error[2];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -708,8 +712,8 @@ class DboMysql extends DboMysqlBase {
|
||||||
* @return integer Number of affected rows
|
* @return integer Number of affected rows
|
||||||
*/
|
*/
|
||||||
function lastAffected() {
|
function lastAffected() {
|
||||||
if ($this->_result) {
|
if ($this->hasResult()) {
|
||||||
return mysql_affected_rows($this->connection);
|
return $this->_result->rowCount();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,20 +235,20 @@ class DboSource extends DataSource {
|
||||||
* - log - Whether or not the query should be logged to the memory log.
|
* - log - Whether or not the query should be logged to the memory log.
|
||||||
*
|
*
|
||||||
* @param string $sql
|
* @param string $sql
|
||||||
|
* @param array $params values to be bided to the query
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return mixed Resource or object representing the result set, or false on failure
|
* @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);
|
$defaults = array('stats' => true, 'log' => $this->fullDebug);
|
||||||
$options = array_merge($defaults, $options);
|
$options = array_merge($defaults, $options);
|
||||||
|
|
||||||
$t = microtime(true);
|
$t = microtime(true);
|
||||||
$this->_result = $this->_execute($sql);
|
$this->_result = $this->_execute($sql, $params);
|
||||||
if ($options['stats']) {
|
if ($options['stats']) {
|
||||||
$this->took = round((microtime(true) - $t) * 1000, 0);
|
$this->took = round((microtime(true) - $t) * 1000, 0);
|
||||||
$this->affected = $this->lastAffected();
|
$this->affected = $this->lastAffected();
|
||||||
$this->error = $this->lastError();
|
//$this->numRows = $this->lastNumRows();
|
||||||
$this->numRows = $this->lastNumRows();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['log']) {
|
if ($options['log']) {
|
||||||
|
@ -576,7 +576,7 @@ class DboSource extends DataSource {
|
||||||
* @return boolean True if the result is valid else false
|
* @return boolean True if the result is valid else false
|
||||||
*/
|
*/
|
||||||
public function hasResult() {
|
public function hasResult() {
|
||||||
return is_resource($this->_result);
|
return is_a($this->_result, 'PDOStatement');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue