Bug #72856 [Opn->Fbk]: incompatible use of odbc and mysql, if connecting with odbc to localhost

From: Date: Fri, 02 Jul 2021 11:41:41 +0000
Subject: Bug #72856 [Opn->Fbk]: incompatible use of odbc and mysql, if connecting with odbc to localhost
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234760@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72856&edit=1

 ID:                 72856
 Updated by:         cmb@php.net
 Reported by:        bugphp at wirelessmundi dot com
 Summary:            incompatible use of odbc and mysql, if connecting
                     with odbc to localhost
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            CGI/CLI related
 Operating System:   debian 8
 PHP Version:        5.6.24
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Is this still an issue with any of the actively supported PHP
versions[1]?

[1] <https://www.php.net/supported-versions.php>


Previous Comments:
------------------------------------------------------------------------
[2016-08-16 15:36:27] bugphp at wirelessmundi dot com

Description:
------------
at some random calls i can't connect to mysql and no error is report back. 
this issue is present with nginx + php-fpm + mysql with multiple sites running on the same server.

After digging, i found that this error is cause by a odbc call from one of the sites. when the odbc
call is done one some php-fpm child and other site tries to connect using mysqli_connect on this
same php-fpm child it simple fails and no error is thrown. the return link is false.

if its relevant, the odbc connection is configure over unixodbc directly to
/var/run/mysqld/mysqld.sock.

i could reproduce the error using simple php script with cli, attached the script to reproduce it.  


I've try to connect to 127.0.0.1 instead of the socket, but i got the same results.




Test script:
---------------
<?php
// when connecting to odbc will make fail all the mysql connections
using_odbc();
sleep(5);
using_mysqli_obj();
using_mysqli();

function using_mysqli()
{
	echo "*** MySQLi \n";
	$link = mysqli_connect("localhost", "root", "m1sq7passwd",
"tel_app", "3306", "/var/run/mysqld/mysqld.sock");
	if (!$link) { echo "Error connecting to MYSQL [".mysqli_connect_errno()."]
".mysqli_connect_error()."\n"; }
	else {
		$result = @mysqli_query($link, "select count(*) as total from client_limit;");
		if (!is_object($result)) {
			echo "no results found, error: ".mysqli_error($link)."\n";
		}
		else {
			$tmp = mysqli_fetch_array($result, MYSQLI_ASSOC);
			mysqli_free_result($result);
			print_r($tmp);
		}
		if (!mysqli_close($link)) {
			echo "Fail to disconnect db link \n";
		}
		unset($link);
	}
	echo "***\n";
}
function using_mysqli_obj() 
{
	echo "*** MySQLi OBJ\n";
	$mysqli = new mysqli('localhost', 'root', 'm1sq7passwd',
'tel_app');
	if ($mysqli->connect_error) { echo ('Connect Error (' . $mysqli->connect_errno .
') '.$mysqli->connect_error); }
	else {
		$result = $mysqli->query("select count(*) as total from client_limit;",
MYSQLI_USE_RESULT);
		if (!is_object($result)) {
			echo "no results found, error: ".$mysqli->error."\n";
		}
		else {
			$tmp = $result->fetch_object();
			print_r($tmp);
			$result->close();
		}
		$mysqli->close();
	}
	echo "*** \n ";
}
function using_odbc()
{
	echo "*** ODBC \n";
	$conn = odbc_connect("localhost_tel_cdr", false, false);
	if (!$conn) { echo "fail to connect using odbc ".odbc_errormsg(); }
	else {
		$res = odbc_exec($conn, "select count(*) as total_cdr from cdr where (start_stamp >=
'1470751734' ) and (start_stamp <= '1471356534' );");
		if (!$res) {
			echo "Fail to execute sql ".odbc_errormsg();
		}
		else {
			$row = odbc_fetch_array($res);
			print_r($row);
			odbc_free_result($res);
		}
		odbc_close($conn);
	}
	echo "***";
}

?>

Expected result:
----------------
*** ODBC 
Array
(
    [total_cdr] => 98
)
*** MySQLi OBJ
stdClass Object
(
    [total] => 216
)
*** 
 *** MySQLi 
Array
(
    [total] => 216
)
***

Actual result:
--------------
*** ODBC 
Array
(
    [total_cdr] => 98
)
****** MySQLi OBJ

Warning: mysqli::query(): Couldn't fetch mysqli in /root/mysql_phpbug.php on line 47

Warning: using_mysqli_obj(): Couldn't fetch mysqli in /root/mysql_phpbug.php on line 49
no results found, error: 

Warning: mysqli::close(): Couldn't fetch mysqli in /root/mysql_phpbug.php on line 56
*** 
 *** MySQLi 
Error connecting to MYSQL [0] 
***


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72856&edit=1


Thread (3 messages)

« previous php.bugs (#234760) next »