fixing unhandled "MySQL server has gone away" in PHP 8.1

This commit is contained in:
ralf 2023-02-18 09:01:07 +01:00
parent 1aef969bc3
commit bbf9d62c5a
2 changed files with 10 additions and 6 deletions

View File

@ -760,8 +760,6 @@ class Db
*/
function query($Query_String, $line = '', $file = '', $offset=0, $num_rows=-1, $inputarr=false, $fetchmode=self::FETCH_BOTH, $reconnect=true)
{
unset($line, $file); // not used anymore
if ($Query_String == '')
{
return 0;
@ -815,14 +813,20 @@ class Db
{
$rs = $this->Link_ID->Execute($Query_String, $inputarr);
}
$this->Errno = 2006;
$this->Error = $this->Link_ID->ErrorMsg();
}
// PHP 8.1 mysqli throws its own exception
catch(\mysqli_sql_exception $e) {
throw new Db\Exception($e->getMessage(), $e->getCode(), $e);
if (!($reconnect && $this->Type == 'mysql' && ($e->getCode() == 2006 || $e->getMessage() === 'MySQL server has gone away')))
{
throw new Db\Exception($e->getMessage(), $e->getCode(), $e);
}
_egw_log_exception($e);
$this->Errno = $e->getCode();
$this->Error = $e->getMessage();
}
$this->Row = 0;
$this->Errno = $this->Link_ID->ErrorNo();
$this->Error = $this->Link_ID->ErrorMsg();
if ($this->query_log && ($f = @fopen($this->query_log,'a+')))
{

View File

@ -79,7 +79,7 @@ function _egw_log_exception($e,&$headline=null)
if(isset($_SERVER['HTTP_HOST']) || $GLOBALS['egw_info']['flags']['no_exception_handler'] !== 'cli')
{
error_log($headline.($e instanceof egw_exception_warning ? ': ' : ' ('.get_class($e).'): ').
$e->getMessage().(!empty($e->details) ? ': '.$e->details : ''));
$e->getMessage().' ('.$e->getCode().')'.(!empty($e->details) ? ': '.$e->details : ''));
error_log('File: '.str_replace(EGW_SERVER_ROOT, '', $e->getFile()).', Line: '.$e->getLine());
foreach($trace as $line)
{