MySQL connection and classes

From: Date: Thu, 22 Jun 2000 15:08:46 +0000
Subject: MySQL connection and classes
Groups: php.general 
Request: Send a blank email to php-general+get-2637@lists.php.net to get a copy of this message
Hi all, I'm at a loss on this one. I wrote this class for pulldown menus and it works great. Unless you connect to different databases in different instances. Apparently the last connection overrides all previous connections, even though each instance *should* have it's own connection. It seems to screw up on the second instance's call to connect. Any ideas? Thanks in advance, Ryan class DataSource { var $dbconn, $tablename; function connect ($host, $db, $login, $password) { $this->dbconn = mysql_pconnect ($host, $login, $password); if (!$this->dbconn) die ("Unable to connect to MySQL Server."); mysql_select_db ($db, $this->dbconn) || die ("Unable to select database"); echo "dbconn: ".$this->dbconn; } function set_table ($tablename) { $this->tablename = $tablename; } function pulldown ($name, $selected="", $value="", $text="", $endquery="", $firstoption="") { $query = "select $value as value, $text as text from ".$this->tablename." $endquery"; // echo $query; // echo "dbconn: ".$this->dbconn; if ($r = mysql_query ($query, $this->dbconn)) { echo "\n\t<select name='$name'>"; echo ($firstoption)? $firstoption: ""; while ($a = mysql_fetch_array ($r)) { if ($a[value] == $selected) $sel = " selected"; else $sel = ""; echo "\n\t\t<option value='$a[value]'$sel>$a[text]</option>"; } echo "\n\t</select>"; } else { echo "<BR>Whoops! Failed...<BR>$query<BR>"; echo mysql_error($this->dbconn); } } } // declare the datasources $ds_contacts = new DataSource; $ds_contacts->connect ("localhost", "fcs", "username", "password"); $ds_contacts->set_table ("personnel"); $ds_pvendors = new DataSource; $ds_pvendors->connect ("localhost", "machine", "username", "password"); $ds_pvendors->set_table ("proc_vendors"); // print the pulldowns $ds_contacts->pulldown ("dataset[m_client_id2]", $dataset[m_client_id2], "UID", "concat(lname, ', ', fname)", "order by lname, fname", "<option value=''>[ NONE ]</option>"); $ds_pvendors->pulldown ("dataset[proc_vendor]", $dataset[proc_vendor], "pv_key", "proc_vendor", "order by proc_vendor", "<option value=''></option>");

« previous php.general (#2637) next »