php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30592 not a valid MySQL-Link resource
Submitted: 2004-10-28 01:52 UTC Modified: 2004-10-29 00:07 UTC
From: v_shiray at ukr dot net Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.9 OS: Linux
Private report: No CVE-ID: None
 [2004-10-28 01:52 UTC] v_shiray at ukr dot net
Description:
------------
Below code has produced next output:

Current connections: Resource id #4, Resource id #4
PHP Warning:  mysql_query(): 4 is not a valid MySQL-Link resource in ...

Tested on Linux Slackware 10.0

PHP Version => 4.3.9
System => Linux gate 2.4.27-lck3 #3 ??? ??? 13 01:00:30 EEST 2004 i686
Build Date => Sep 30 2004 23:01:51
Configure Command =>  './configure' '--prefix=/opt/php' '--with-config-file-path=/opt/php/etc' '--disable-cgi' '--enable-static' '--disable-shared' '--enable-sockets' '--enable-ftp' '--with-mysql=/usr' '--with-zlib=/usr'

PS. PHP 4.3.6 and 4.3.7 are not affected for this problem.


Reproduce code:
---------------
error_reporting(E_ALL);

$db1 = mysql_connect ('localhost', 'test', '1');
$db2 = mysql_connect ('localhost', 'test', '1');

echo "Current connections: $db1, $db2\n";
mysql_close($db2);
$db2 = 0;

mysql_query('SELECT 1+1', $db1);


Expected result:
----------------
Resource ID must be available with $db1



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-28 03:01 UTC] v_shiray at ukr dot net
MySQL 4.0.20

Problem has been detected also with
   PHP 4.3.8 and 5.0.2 on the same computer
   RedHat 9.0, MySQL 3.23.58, PHP 4.3.9
 [2004-10-28 07:22 UTC] georg@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

See http://www.php.net/mysql_connect 
 [2004-10-28 18:36 UTC] v_shiray at ukr dot net
I had read manual many time before submitinig the "bug".
So as you said it's a normal behavior but it's very strange as for me.
Maybe you will have time to answer on  some questions.

Why do this behaviour different between versions of PHP,
e.g 4.3.6 and 4.3.9 ?

How can I unset $db2 without triggering this "problem"?
So I may change
  $db2 = 0;
to
  unset($db2);
with the same effect.
 [2004-10-28 19:03 UTC] radical@php.net
If you want to open a new link to a MySQL server you must specify the 4th param to mysql_connect witch is a boolean that has a default value of FALSE.

$link_1 = mysql_connect('host', 'user', 'pass');
$link_2 = mysql_connect('host', 'user', 'pass', TRUE);

Only this is the way to create a new link to MySQL... otherwise PHP will just return the old one... but only if mysql_connect's parrams are the same !

This 4th param was introduced as of PHP 4.2.0.

To work on the $link_1 you should specify it...

mysql_query("SELECT ...", $link_1);

because otherwise PHP will use $link_2... akka the last opened link !

Good fortune ! I hope it's clear !
 [2004-10-28 20:03 UTC] v_shiray at ukr dot net
Hmm. I did not say ANYTIME about opening a new link to MySQL.
It's very strange that you take care on this.
Please reread my initial submission.

I noticed about a possible 'bug' with resource freeing.

Provided source will work perfectly if
I will comment next line:
// $db2 = 0;

It's a very strange 'behaviour' as for me!
Do you think on other ?
 [2004-10-29 00:07 UTC] derick@php.net
And this is NOT a bug. You're doing something wrong here, ask on php-general@lists.php.net about it. This bug system is not a forum.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 17:01:29 2024 UTC