Cope with mysql errors even with php ver. < 8; check if $link is false before trying to close mysql connection in function mexit

This commit is contained in:
pezcurrel 2022-12-16 22:39:51 +01:00
parent e46a82d923
commit b46469bfbb

View file

@ -832,8 +832,8 @@ function myq(&$link,$query,$line) {
catch (Exception $error) {
mexit('query «'.$query.'» (line '.$line.') failed: '.$error->getMessage().N,3);
}
// for older php versions, which seem to not catch mysql exceptions
if ($res===false) mexit('query «'.$query.'» (line '.$line.') failed: '.mysqli_errno($link).': '.mysqli_error($link).N,3);
// for php versions < 8, which seem to not catch mysql exceptions
if ($res===false) mexit('query «'.$query.'» (line '.$line.') failed: '.mysqli_errno($link).': '.mysqli_error($link).'.'.N,3);
return($res);
}
@ -854,7 +854,7 @@ function eecho($lev,$msg) {
function mexit($msg,$code) {
global $link, $jsonf, $logf, $lockfp;
if (isset($link)) mysqli_close($link);
if (isset($link) && $link!==false) mysqli_close($link);
if (isset($jsonf) && $jsonf!==false) fclose($jsonf);
if (isset($logf) && $logf!==false) fclose($logf);
if (isset($lockfp) && is_file($lockfp)) unlink($lockfp);