php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72856 incompatible use of odbc and mysql, if connecting with odbc to localhost
Submitted: 2016-08-16 15:36 UTC Modified: 2021-07-11 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: bugphp at wirelessmundi dot com Assigned: cmb (profile)
Status: No Feedback Package: CGI/CLI related
PHP Version: 5.6.24 OS: debian 8
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bugphp at wirelessmundi dot com
New email:
PHP Version: OS:

 

 [2016-08-16 15:36 UTC] 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] 
***

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-02 11:41 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-07-02 11:41 UTC] cmb@php.net
Is this still an issue with any of the actively supported PHP
versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-07-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 15:01:32 2024 UTC