[php-src] Issue #11579: Connect Error Over Multiple MySQLi Objects

From: Date: Mon, 03 Jul 2023 01:36:35 +0000
Subject: [php-src] Issue #11579: Connect Error Over Multiple MySQLi Objects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244865@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11579
Author: malcmal

### Description

The following code will setup the circumstances to highlight the issue. It requires that you have
the ability to connect to three different MySQL servers via IP. It can be done with only two but the
bug is easier to spot when you have three:

<?php

$db_user = "username";
$db_pass = "password";
$db_host1 = "1.2.3.4";
$db_host2 = "2.3.4.5";
$db_host3 = "3.4.5.6";

mysqli_report(MYSQLI_REPORT_OFF);

$server1 = mysqli_init();
$server1->options(MYSQLI_OPT_CONNECT_TIMEOUT, 1);

$server2 = mysqli_init();
$server2->options(MYSQLI_OPT_CONNECT_TIMEOUT, 1);

$server3 = mysqli_init();
$server3->options(MYSQLI_OPT_CONNECT_TIMEOUT, 1);

$server1->real_connect($db_host1, $db_user, $db_pass);
$server2->real_connect($db_host2, $db_user, $db_pass);
$server3->real_connect($db_host3, $db_user, $db_pass);


echo "Server 1 Connect Error Number: {$server1->connect_errno}\n<BR>";
echo "Server 1 Error Number: {$server1->errno}\n<BR>";
echo "\n<BR>";
echo "Server 2 Connect Error Number: {$server2->connect_errno}\n<BR>";
echo "Server 2 Error Number: {$server2->errno}\n<BR>";
echo "\n<BR>";
echo "Server 3 Connect Error Number: {$server3->connect_errno}\n<BR>";
echo "Server 3 Error Number: {$server3->errno}\n<BR>";


?>

The issue is with the error reporting when one of the servers is unreachable. If it's the last
one in the list then ALL servers show an error code in a very random fashion. An example output
would be:

Server 1 Connect Error Number: 2002
Server 1 Error Number: 0

Server 2 Connect Error Number: 2002
Server 2 Error Number: 0

Server 3 Connect Error Number: 2002
Server 3 Error Number: 2002

This is despite the fact that servers 1 and 2 were successfully connected and able to process
queries. It seems to me that the error reporting is completely broken.

### PHP Version

PHP 8.2.7

### Operating System

OpenBSD 7.3


Thread (1 message)

  • malcmal
« previous php.bugs (#244865) next »