php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13940 mysql_select_db doesn't honor resource_identifier param
Submitted: 2001-11-05 19:19 UTC Modified: 2001-11-21 13:26 UTC
From: cnewbill at elementalrain dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.2.0-dev OS: RedHat 7.1
Private report: No CVE-ID: None
 [2001-11-05 19:19 UTC] cnewbill at elementalrain dot com
I need multiple connections to the same MySQL server to two different databases and mysql_select_db() is not honoring the resource_identifier, it is using the one of that last connection opened.

//script
<?php

// test mysql_select_db with two active connections

$conn1 = mysql_connect("localhost", "root" ,"#rain!");

if (!$conn1) {
    print "Could not connect to server one\n";
} else {
    if (!mysql_select_db("st2", $conn1))
        print "Could not select DB on server one ".mysql_error($conn1)."\n";
}

$conn2 = mysql_connect("localhost", "root" ,"#rain!");

if (!$conn2) {
    print "Could not connect to server two\n";
} else {
    if (!mysql_select_db("commercesys", $conn2))
        print "Could not select DB on server two ".mysql_error($conn2)."\n";
}

if (!mysql_query("select * from user", $conn1)) {
    print "Could not issue query to conn1 ".mysql_error($conn1)."\n";
}

if (!mysql_query("select * from customer", $conn2)) {
    print "Could not issue query to conn2 ".mysql_error($conn2)."\n";
}

?>

OUTPUT:
Could not issue query to conn1 Table 'commercesys.user' doesn't exist

If you flip the connect blocks you get:
Could not issue query to conn2 Table 'st2.customer' doesn't exist

I'll look at the source, but this is not too cool.

-Chris

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-05 19:42 UTC] cnewbill at elementalrain dot com
I can already hear the lame 'expected behavior, use mysql_select_db() before each query, blah, blah' excuses coming, but...

If you are able to set "properties" per connection resource, one would think that those "properties" stay with that connection resource and do not get overriden by setting "properties" for other connection resources.  This implementation seems rather misleading.  Not sure where to point the finger here, Zend Resource Management???

-Chris

yes I am aware I copy+pasted passwords, they are changed , not that you can access that server anyways :) 
 [2001-11-20 18:42 UTC] mfischer@php.net
This is basically a dup of #14137, bogusifying this one.
 [2001-11-20 19:15 UTC] cnewbill@php.net
Ehh not bogus.  Like you said is a dupe.  Even though I reported it before 14137.

Oh well,
-Chris
 [2001-11-21 13:26 UTC] sniper@php.net
No need for two reports about same issue.

 [2010-03-12 03:50 UTC] lovedone97 at hotmail dot com
Hello. Hollywood is a place where they place you under contract instead of under observation. Help me! Please help find sites for: Stock trading log. I found only this - <a href="http://www.fabrikant-records.net/Members/StockTrading/free-online-penny-stock-trading-system">free online penny stock trading system</a>. Stock trading, then, options and sports are normally listed. Stock trading, future investors are not learnt to as advanced hpt if they trade areas for their examples in economic sites around the property, getting their own compensatory networks or many low term dollars in each stock to limit flatcars for their pushing receivers. Thank you very much :eek:. Forster from Iran.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC