mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding try catch for pdo exception on DboSource::_execute
This commit is contained in:
parent
130fe603a7
commit
a791687784
2 changed files with 18 additions and 25 deletions
|
@ -207,19 +207,6 @@ class DboSqlite extends DboSource {
|
|||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes given SQL statement.
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @param array $params list of params to be bound to query
|
||||
* @return PDOStatement if query executes with no problem, true as the result of a succesfull
|
||||
* query returning no rows, suchs as a CREATE statement, false otherwise
|
||||
*/
|
||||
protected function _execute($sql, $params = array()) {
|
||||
$this->_result = parent::_execute($sql, $params);
|
||||
return $this->_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and executes an SQL UPDATE statement for given model, fields, and values.
|
||||
*
|
||||
|
|
|
@ -344,19 +344,25 @@ class DboSource extends DataSource {
|
|||
}
|
||||
}
|
||||
|
||||
$query = $this->_connection->prepare($sql);
|
||||
$query->setFetchMode(PDO::FETCH_LAZY);
|
||||
if (!$query->execute($params)) {
|
||||
$this->_results = $query;
|
||||
$this->error = $this->lastError($query);
|
||||
$query->closeCursor();
|
||||
return false;
|
||||
try {
|
||||
$query = $this->_connection->prepare($sql);
|
||||
$query->setFetchMode(PDO::FETCH_LAZY);
|
||||
if (!$query->execute($params)) {
|
||||
$this->_results = $query;
|
||||
$this->error = $this->lastError($query);
|
||||
$query->closeCursor();
|
||||
return false;
|
||||
}
|
||||
if (!$query->columnCount()) {
|
||||
$query->closeCursor();
|
||||
return true;
|
||||
}
|
||||
return $query;
|
||||
} catch (PDOException $e) {
|
||||
$this->_results = null;
|
||||
$this->error = $e->getMessage();
|
||||
}
|
||||
if (!$query->columnCount()) {
|
||||
$query->closeCursor();
|
||||
return true;
|
||||
}
|
||||
return $query;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue