#35993 [Opn->Bgs]: mysql_query doesnt honor database resource id

From: Date: Fri, 13 Jan 2006 17:30:18 +0000
Subject: #35993 [Opn->Bgs]: mysql_query doesnt honor database resource id
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-91861@lists.php.net to get a copy of this message
ID: 35993 Updated by: tony2001@php.net Reported By: andreas at fink dot org -Status: Open +Status: Bogus Bug Type: MySQL related Operating System: MacOS X & Linux PHP Version: 5.1.2 New Comment: >$db1_handle=mysql_pconnect("127.0.0.1","test","test"); >$db2_handle=mysql_pconnect("127.0.0.1","test","test", true); Do you read what I'm writing or you just ignore it? Try to open the docs and read whether the 4th parameter of mysql_Pconnect() is the same as the 4th parameter of mysql_Connect(). Again, you're using THE SAME PERSISTENT CONNECTION returned by Pconnect(). Please stop reopening this report, there is no bug. Previous Comments: ------------------------------------------------------------------------ [2006-01-13 18:19:47] andreas at fink dot org Gosh. Please CHECK what I provided before putting it to bogous again. THIS IS DEFINITIVELY A BUG. It just doesnt occur in all scenarios. Your code works here too but mine doesn't and its not obvious why not. It apparently depends what you do with Mysql and what user you use. Test EXACTLY THIS and not with user "root" or anything else: 1st. rename table testdata to testdata2 in database test2 2nd: <?php $db1_handle=mysql_pconnect("127.0.0.1","test","test"); mysql_select_db("test1",$db1_handle); $db2_handle=mysql_pconnect("127.0.0.1","test","test", true); mysql_select_db("test2",$db2_handle); $query = "show tables"; $result1 = mysql_query($query,$db1_handle); while ($line = mysql_fetch_row ( $result1 ) ) { var_dump($line); } echo "---------------------------\n"; $query = "show tables"; $result2 = mysql_query($query,$db2_handle); while ($line = mysql_fetch_row ( $result2 ) ) { var_dump($line); } ?> results in: vpn5:~ afink$ php test2.php array(1) { [0]=> string(8) "testdata" } --------------------------- array(1) { [0]=> string(8) "testdata" } The SECOND one however MUST BE "testdata2" So its doing it at the WRONG DB. mysql> use test1 Database changed mysql> show tables; +-----------------+ | Tables_in_test1 | +-----------------+ | testdata | +-----------------+ 1 row in set (0.01 sec) mysql> use test2 Database changed mysql> show tables; +-----------------+ | Tables_in_test2 | +-----------------+ | testdata2 | +-----------------+ 1 row in set (0.00 sec) mysql> ------------------------------------------------------------------------ [2006-01-13 17:58:28] tony2001@php.net <?php $db1_handle=mysql_connect("127.0.0.1","root","", true); mysql_select_db("test",$db1_handle); $db2_handle=mysql_connect("127.0.0.1","root","", true); mysql_select_db("mysql",$db2_handle); $query = "show tables"; $result1 = mysql_query($query,$db1_handle); while ($line = mysql_fetch_row ( $result1 ) ) { var_dump($line); } echo "---------------------------\n"; $query = "show tables"; $result2 = mysql_query($query,$db2_handle); while ($line = mysql_fetch_row ( $result2 ) ) { var_dump($line); } ?> This code works perfectly here. ------------------------------------------------------------------------ [2006-01-13 15:14:21] andreas at fink dot org Tried the suggestion in two ways: $db1_handle=mysql_connect("127.0.0.1","test","test",1); mysql_select_db("test1",$db1_handle); $db2_handle=mysql_connect("127.0.0.1","test","test",1); mysql_select_db("test2",$db2_handle); result: This query was executed on db1_handle:This is DB named test1 This query was executed on db2_handle:This is DB named test1 so still wrong if I use mysql_connect instead I get This query was executed on db1_handle:This is DB named test1 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /Users/afink/test.php on line 14 This query was executed on db2_handle: So it is still a bug. ------------------------------------------------------------------------ [2006-01-13 12:43:19] tony2001@php.net $db1_handle=mysql_pconnect("127.0.0.1","test","test"); $db2_handle=mysql_pconnect("127.0.0.1","test","test"); These two calls effectively return THE SAME connection identifier (because connect details are the same). Use mysql_connect() with 4th parameter set to TRUE to force creation of new connection. No bug here. ------------------------------------------------------------------------ [2006-01-13 12:14:49] andreas at fink dot org used configure statement: export CC="gcc" export CFLAGS="-DBIND_8_COMPAT=1 -DEAPI -O3 -fno-omit-frame-pointer" ./configure --mandir=/usr/share/man --with-mysql=/usr/local/mysql \ --enable-dba --enable-track-vars --with-sockets \ -enable-libxml --enable-calendar --enable-ftp \ --with-apxs=/usr/sbin/apxs --enable-cli --disable-cgi \ --disable-dependency-tracking ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/35993 -- Edit this bug report at http://bugs.php.net/?id=35993&edit=1

« previous php.bugs (#91861) next »