Re: MySQL connection and classes

From: Date: Thu, 22 Jun 2000 17:33:00 +0000
Subject: Re: MySQL connection and classes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-2670@lists.php.net to get a copy of this message
Thanks, man. It works if I use different usernames/passwords for different instances. Unfortunately, I only have 2 usernames/passwords that I can use in these scripts, and several pulldown menus. I'll probably use that specify the database in the query method. Still not where I wanted it to be though. Maybe I'm just a perfectionist... Thanks again, Ryan On Thu, Jun 22, 2000 at 04:47:50PM +0100, Stewart Taylor wrote: > Try accessing each database using a differnet username and password and > specify database name in your queries. > e.g. > select * from database.tablename > > -Stewart > > > -----Original Message----- > From: Ryan Adams [mailto:radams@fcs.uga.edu] > Sent: 22 June 2000 16:09 > To: php-general@lists.php.net > Subject: [PHP-GENERAL] MySQL connection and classes > > > 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>"); > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ---end quoted text---

« previous php.general (#2670) next »