|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-23 13:24 UTC] tony2001@php.net
[2006-08-23 13:29 UTC] warden at warden dot cz
[2006-08-23 13:33 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 20:00:02 2025 UTC |
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.