From de71df9df2c4fd0f69501e1afcee3fbf25e56216 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 4 Jul 2022 03:06:56 +0200 Subject: [PATCH] Debug install v16 with php 8.1 --- htdocs/core/db/mysqli.class.php | 29 +++++++++++++------ htdocs/core/db/pgsql.class.php | 6 +++- ...ql => llx_c_asset_disposal_type-asset.sql} | 0 htdocs/install/step4.php | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) rename htdocs/install/mysql/data/{llx_c_asset_disposal_type.sql => llx_c_asset_disposal_type-asset.sql} (100%) diff --git a/htdocs/core/db/mysqli.class.php b/htdocs/core/db/mysqli.class.php index 582fd08811f..593a9454b6f 100644 --- a/htdocs/core/db/mysqli.class.php +++ b/htdocs/core/db/mysqli.class.php @@ -92,14 +92,14 @@ class DoliDBMysqli extends DoliDB // We do not try to connect to database, only to server. Connect to database is done later in constrcutor $this->db = $this->connect($host, $user, $pass, '', $port); - if ($this->db->connect_errno) { - $this->connected = false; - $this->ok = false; - $this->error = $this->db->connect_error; - dol_syslog(get_class($this)."::DoliDBMysqli Connect error: ".$this->error, LOG_ERR); - } else { + if ($this->db && empty($this->db->connect_errno)) { $this->connected = true; $this->ok = true; + } else { + $this->connected = false; + $this->ok = false; + $this->error = empty($this->db) ? 'Failed to connect' : $this->db->connect_error; + dol_syslog(get_class($this)."::DoliDBMysqli Connect error: ".$this->error, LOG_ERR); } // If server connection is ok, we try to connect to the database @@ -204,7 +204,12 @@ class DoliDBMysqli extends DoliDB { // phpcs:enable dol_syslog(get_class($this)."::select_db database=".$database, LOG_DEBUG); - return $this->db->select_db($database); + $result = false; + try { + $result = $this->db->select_db($database); + } catch (Exception $e) { + } + return $result; } @@ -216,7 +221,7 @@ class DoliDBMysqli extends DoliDB * @param string $passwd Password * @param string $name Name of database (not used for mysql, used for pgsql) * @param integer $port Port of database server - * @return mysqli Database access object + * @return mysqli|null Database access object * @see close() */ public function connect($host, $login, $passwd, $name, $port = 0) @@ -228,7 +233,13 @@ class DoliDBMysqli extends DoliDB // Can also be // mysqli::init(); mysql::options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0'); mysqli::options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); // return mysqli::real_connect($host, $user, $pass, $db, $port); - return new mysqli($host, $login, $passwd, $name, $port); + $tmp = false; + try { + $tmp = new mysqli($host, $login, $passwd, $name, $port); + } catch (Exception $e) { + dol_syslog(get_class($this)."::connect failed", LOG_DEBUG); + } + return $tmp; } /** diff --git a/htdocs/core/db/pgsql.class.php b/htdocs/core/db/pgsql.class.php index 5a2a1c1b753..fe3269867a9 100644 --- a/htdocs/core/db/pgsql.class.php +++ b/htdocs/core/db/pgsql.class.php @@ -419,7 +419,11 @@ class DoliDBPgsql extends DoliDB // try first Unix domain socket (local) if ((!empty($host) && $host == "socket") && !defined('NOLOCALSOCKETPGCONNECT')) { $con_string = "dbname='".$name."' user='".$login."' password='".$passwd."'"; // $name may be empty - $this->db = @pg_connect($con_string); + try { + $this->db = @pg_connect($con_string); + } catch (Exception $e) { + // No message + } } // if local connection failed or not requested, use TCP/IP diff --git a/htdocs/install/mysql/data/llx_c_asset_disposal_type.sql b/htdocs/install/mysql/data/llx_c_asset_disposal_type-asset.sql similarity index 100% rename from htdocs/install/mysql/data/llx_c_asset_disposal_type.sql rename to htdocs/install/mysql/data/llx_c_asset_disposal_type-asset.sql diff --git a/htdocs/install/step4.php b/htdocs/install/step4.php index c8be975c19f..1bd7665f52a 100644 --- a/htdocs/install/step4.php +++ b/htdocs/install/step4.php @@ -80,7 +80,7 @@ $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf if ($db->ok) { print ''; - print ''; + print ''; print ''; print ''; print '';