php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38563 Can't make 2 instances of mysql class, each has to connect another server
Submitted: 2006-08-23 13:18 UTC Modified: 2006-08-23 13:33 UTC
From: warden at warden dot cz Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.4.4 OS: Gentoo Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: warden at warden dot cz
New email:
PHP Version: OS:

 

 [2006-08-23 13:18 UTC] warden at warden dot cz
Description:
------------
I have a mysql class. When I create an instance, constructor makes connection to server. Then I can use methods to do something with this connection. If I make 2 instances in the same script and each instance is created to connect to another server, the second connection resource rewrites resource in first class.

Reproduce code:
---------------
PART OF USING:

$this->sql = new c_mySqlEx("first", "frs_svr", "login", "pass");
$this->secondSql = new c_mySqlEx("second", "sec_svr", "login", "pass");

$server_select = $this->sql->dbQuery("db", "query");
$server_record = $this->sql->fetchArray($server_select);

PART OF CLASS:

class c_mySql {
    var $identify;
    var $server;
    var $login;
    var $pass;
    var $connection;
    
    /* cons */
    function c_mySql($conIdentify = "", $conServer = "", $conLogin = "", $conPass = ""){
        $this->identify = $conIdentify;
        $this->server = $conServer;
        $this->login = $conLogin;
        $this->pass = $conPass;
        
        $this->connect();
    }
    
    /* connect */
    function connect(){
        $this->connection = mysql_connect($this->server, $this->login, $this->pass);
        if (!$this->connection){
            echo "error...";
        }
    }

    function dbQuery($db, $query){
        $mysqlDBQuery = MySQL_DB_Query($db, $query);
        if (!$mysqlDBQuery){
            echo "error...";
        }
        else {
            return $mysqlDBQuery;
        }
    }

    function fetchArray($result, $errMode = 1){
        @$mysqlFetchArray = MySQL_Fetch_Array($result);
        if ((!$mysqlFetchArray) && ($errMode == 1)){
            echo "error...";
        }
        else {
            return $mysqlFetchArray;
        }
    }

........

Expected result:
----------------
Each instance can work with mysql on the expected (another) server.

Actual result:
--------------
The second connect resource (in the second resource) rewrites resource in the first instance.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-23 13:24 UTC] tony2001@php.net
Use 4th parameter of mysql_connect().
 [2006-08-23 13:29 UTC] warden at warden dot cz
I tried, but nothing happend...
 [2006-08-23 13:33 UTC] tony2001@php.net
Because you also need to specify the connection identifier in all mysql_*() functions.
Please do not reopen the report and read the docs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 10:01:28 2024 UTC