Jump to content

OO Var Collision, Am I going CrAzY???


drtyrell

Recommended Posts

Okay, real simple issue, hopefully someone has a simple solution. I have a single web page that needs to connect to TWO different databases. I've written everything in OO, and I'm getting a crazy situation where vars seem to be bleeding into each other. The problem goes like follows:

 

I declare two SEPARATE database instances like so:

 

require_once '/blah/classes/db/class.DBCMS.php';
require_once '/blah/classes/db/class.DBC.php';

$db1			= new DBC();
$db2			= new DBCMS();

 

I then pass in the $db(n) variables to a separate class to be used to process data like so:

 

$publisher		= new htmlCreator1($db1);
$publisher		= new htmlCreator2($db2);

 

My problem is thus: INSIDE the respective different classes, my references to the $db vars seem to be colliding between instances. So $this->db->connection from db2 is referencing db1. The objects are defined like so:

 

class htmlCreator1
{
     var $db;
     function __construct($db)
    {
        $this->db = $db;
     }
}

 

Shouldn't the respective $this->db's maintain their own namespace without extra work? I'm getting errors saying that tables in db2 aren't in db1 because of this collision as per the internal db instance vars. I have experimented with renaming all respective vars to unique names and still get the error.

 

I'm crazy aren't I?

 

Any help would be greatly appreciated.

 

Thx,

 

Dr.

 

 

Link to comment
Share on other sites

Alright you geniuses. Here's the solution found on stackoverlfow dot com:

 

"The next parameter to mysql_connect is $new_link, can you try sending in a true there and see if it helps?

 

$this->connection = mysql_connect($host, $username, $password, true);"

 

With TRUE one gets unique connection objects. If you don't know, just say you don't know.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.