Check query return value in db_cache_value()

Instead of unconditionally calling fetch on the return value of query(),
error out early if the value evaluates to false.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2017-04-18 08:36:29 +02:00
parent 6090c2ae8b
commit 4f662c773d

View file

@ -73,6 +73,9 @@ function db_cache_value($dbq, $key, $ttl=600) {
$value = get_cache_value($key, $status); $value = get_cache_value($key, $status);
if (!$status) { if (!$status) {
$result = $dbh->query($dbq); $result = $dbh->query($dbq);
if (!$result) {
return false;
}
$row = $result->fetch(PDO::FETCH_NUM); $row = $result->fetch(PDO::FETCH_NUM);
$value = $row[0]; $value = $row[0];
set_cache_value($key, $value, $ttl); set_cache_value($key, $value, $ttl);