php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38689 2 connections with same server/auth selecting diff dbs
Submitted: 2006-09-02 05:07 UTC Modified: 2006-09-02 12:41 UTC
From: nerdystudmuffin at gmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.1.6 OS: Linux, XP, NT, 2K
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: nerdystudmuffin at gmail dot com
New email:
PHP Version: OS:

 

 [2006-09-02 05:07 UTC] nerdystudmuffin at gmail dot com
Description:
------------
Generating two database handles to the same server with the same authentication and selecting different databases for them. They act as a single connection and will only return results from the last database selected.

Reproduce code:
---------------
$server ="localhost";
$user="sql_admin";
$pass="password";
$num_query = "SELECT * FROM aqs_users WHERE 1";
$num_db = "aqs";
$anum_query = "SELECT * FROM w_dagent_hierarchy WHERE row_date='2005-08-08'";
$anum_db = "dbviews";
$num = mysql_connect($server,$user,$pass);
$anum = mysql_connect($server,$user,$pass);
### LINEAR
mysql_select_db($num_db,$num);
mysql_select_db($anum_db,$anum);
$num_res = mysql_query($num_query,$num);
$anum_res = mysql_query($anum_query,$anum);
$num_row = mysql_fetch_row($num_res);
$anum_row = mysql_fetch_row($anum_res);
echo "<pre>"; print_r($num_row); echo "</pre>";
echo "<pre>"; print_r($anum_row); echo "</pre>";
mysql_close($num); mysql_close($anum); unset($num_res); unset($anum_res); unset($num_row); unset($anum_row);
echo "<hr>";
$num = mysql_connect($server,$user,$pass);
$anum = mysql_connect($server,$user,$pass);
mysql_query("USE aqs",$num);
mysql_query("USE dbviews",$anum);
$num_res = mysql_query($num_query,$num);
$anum_res = mysql_query($anum_query,$anum);
$num_row = mysql_fetch_row($num_res);
$anum_row = mysql_fetch_row($anum_res);
echo "<pre>"; print_r($num_row); echo "</pre>";
echo "<pre>"; print_r($anum_row); echo "</pre>";
mysql_close($num); mysql_close($anum); unset($num_res); unset($anum_res); unset($num_row); unset($anum_row);

Expected result:
----------------
I would expect both querys to run and display a formatted print_r() of the results.

Actual result:
--------------
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in D:\AQS\testme.php on line 64

Array
(
    [0] => 1
    [1] => CENSORED
    [2] => CENSORED
    [3] => 15
    [4] => 0
    [5] => 4
)


Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in D:\AQS\testme.php on line 82

Array
(
    [0] => 2005-08-08
    [1] => 0011f25.0000010
    [2] => 2300
    [3] => CENSORED
    [4] => 
    [5] => CENSORED
    [6] => CENSORED
    [7] => 0021d02.0000004
    [8] => Mid
    [9] => CENSORED
    [10] => CENSORED
    [11] => Full-time
    [12] => CENSORED
    [13] => 2003-12-08
    [14] => 0000-00-00
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-02 05:13 UTC] judas dot iscariote at gmail dot com
this is actually the expected behaviuor.

use the 4th parameter of mysql_connect see :

http://php.net/manual/en/function.mysql-connect.php

not a bug, but a feature. ;)
 [2006-09-02 06:38 UTC] tony2001@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


 [2006-09-02 12:41 UTC] nerdystudmuffin at gmail dot com
What a waste of your time, I'm sorry I scoured Google and other resources for this issue and didn't find it anywhere. My fellow programmers locally were all scratching their heads ... even IRC had no answers(rarely has anything of value these days). 

[QUOTE]
this is actually the expected behaviuor.
use the 4th parameter of mysql_connect see :
[/QUOTE]

This fixed my problem. Thank you for the solution. The logic behind this makes sense although it wasn't expected behavior. I will now attempt to remove my ass-hat ;)

Cheers!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 17:01:29 2024 UTC