You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's possible for the prepare() call on this line to fail and return a boolean value of false (e.g. if the database is missing the relevant table), but there's no check for this (e.g. one equivalent to the one for the execute() call below it).
Here's an example of a refactor that might add this check:
/** * Fetch the data matching the results of the SQL operation * * @param string $sql SQL statement * @param array $data Data to use in fetch operation * @param boolean $single Only fetch a single record * @return array Fetched data */publicfunctionfetch($sql, array$data = array(), $single = false)
{
$sth = $this->getDb()->prepare($sql);
if ($this->isFailure($sth, $sth)) {
returnfalse;
}
$result = $sth->execute($data);
if ($this->isFailure($sth, $result)) {
returnfalse;
}
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
return ($single === true) ? array_shift($results) : $results;
}
/** * @param PDOStatement|boolean $sth * @param mixed $result * @return boolean TRUE if $result indicates failure, FALSE otherwise */privatefunctionisFailure($sth, $result)
{
if ($result === false) {
$error = $sth->errorInfo();
$this->lastError = 'DB ERROR: ['.$sth->errorCode().'] '.$error[2];
error_log($this->lastError);
returntrue;
}
returnfalse;
}
The text was updated successfully, but these errors were encountered:
It's possible for the
prepare()
call on this line to fail and return a boolean value offalse
(e.g. if the database is missing the relevant table), but there's no check for this (e.g. one equivalent to the one for theexecute()
call below it).Here's an example of a refactor that might add this check:
The text was updated successfully, but these errors were encountered: