From 7540720c79926106a6693f00ba0420df4a08f8f1 Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 16 Dec 2024 20:04:33 +0700 Subject: [PATCH 1/2] [ticket/17455] Fix PHP warning on MySQLi connection failure PHPBB-17455 --- phpBB/phpbb/db/driver/mysqli.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/db/driver/mysqli.php b/phpBB/phpbb/db/driver/mysqli.php index 6182801da6..9e2e9a9926 100644 --- a/phpBB/phpbb/db/driver/mysqli.php +++ b/phpBB/phpbb/db/driver/mysqli.php @@ -63,10 +63,10 @@ class mysqli extends \phpbb\db\driver\mysql_base if (!@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS)) { - $this->db_connect_id = ''; + $this->connect_error = 'Failed to establish a connection to the MySQL database engine. Please ensure MySQL server is running and the database configuration parameters are correct.'; } - if ($this->db_connect_id && $this->dbname != '') + if (!$this->connect_error && $this->db_connect_id && $this->dbname != '') { // Disable loading local files on client side @mysqli_options($this->db_connect_id, MYSQLI_OPT_LOCAL_INFILE, false); From 059e82de8f5e43f993f9336c982d2556efcab24d Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 2 Jan 2025 17:33:41 +0700 Subject: [PATCH 2/2] [ticket/17455] Remove outdated mysqli_connect_error function existence check PHPBB-17455 --- phpBB/phpbb/db/driver/mysqli.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/phpBB/phpbb/db/driver/mysqli.php b/phpBB/phpbb/db/driver/mysqli.php index 9e2e9a9926..0f4a6e8628 100644 --- a/phpBB/phpbb/db/driver/mysqli.php +++ b/phpBB/phpbb/db/driver/mysqli.php @@ -59,9 +59,12 @@ class mysqli extends \phpbb\db\driver\mysql_base } } - $this->db_connect_id = mysqli_init(); + if (!$this->db_connect_id = mysqli_init()) + { + $this->connect_error = 'Failed to initialize MySQLi object.'; - if (!@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS)) + } + else if (!@mysqli_real_connect($this->db_connect_id, $this->server, $this->user, $sqlpassword, $this->dbname, $port, $socket, MYSQLI_CLIENT_FOUND_ROWS)) { $this->connect_error = 'Failed to establish a connection to the MySQL database engine. Please ensure MySQL server is running and the database configuration parameters are correct.'; } @@ -357,15 +360,8 @@ class mysqli extends \phpbb\db\driver\mysql_base if ($this->db_connect_id) { $error = [ - 'message' => $this->db_connect_id->error, - 'code' => $this->db_connect_id->errno, - ]; - } - else if (function_exists('mysqli_connect_error')) - { - $error = [ - 'message' => $this->db_connect_id->connect_error, - 'code' => $this->db_connect_id->connect_errno, + 'message' => $this->db_connect_id->connect_error ?: $this->db_connect_id->error, + 'code' => $this->db_connect_id->connect_errno ?: $this->db_connect_id->errno, ]; } else