fix PHP 8.x throws mysqli_sql_exception when it can not connect

This commit is contained in:
ralf 2022-09-09 08:24:20 +02:00
parent f1cba99aa9
commit b13c1d97b4

View File

@ -544,10 +544,12 @@ class Db
($Type !== 'mysqli' || ini_get('mysqli.allow_persistent')) ? ($Type !== 'mysqli' || ini_get('mysqli.allow_persistent')) ?
'PConnect' : 'Connect'; 'PConnect' : 'Connect';
try
{
if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database))) if (($Ok = $this->Link_ID->$connect($Host, $User, $Password, $Database)))
{ {
$this->ServerInfo = $this->Link_ID->ServerInfo(); $this->ServerInfo = $this->Link_ID->ServerInfo();
$this->set_capabilities($Type,$this->ServerInfo['version']); $this->set_capabilities($Type, $this->ServerInfo['version']);
// switch off MySQL 5.7+ ONLY_FULL_GROUP_BY sql_mode // switch off MySQL 5.7+ ONLY_FULL_GROUP_BY sql_mode
if (substr($this->Type, 0, 5) == 'mysql' && (float)$this->ServerInfo['version'] >= 5.7 && (float)$this->ServerInfo['version'] < 10.0) if (substr($this->Type, 0, 5) == 'mysql' && (float)$this->ServerInfo['version'] >= 5.7 && (float)$this->ServerInfo['version'] < 10.0)
@ -555,6 +557,11 @@ class Db
$this->query("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))", __LINE__, __FILE__); $this->query("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))", __LINE__, __FILE__);
} }
} }
}
catch (\mysqli_sql_exception $e) {
_egw_log_exception($e);
$Ok = false;
}
if (!$Ok) if (!$Ok)
{ {
$Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password $Host = preg_replace('/password=[^ ]+/','password=$Password',$Host); // eg. postgres dsn contains password