Collegiate Acappella :: home :: Beau Sia - APIA Vote
I'm writing a little app for work and trying to keep things as clean and extensible as possible. So of course, I want to abstract the user credentials out to its own class and database since I don't want to annoy the heck out of my users and have them sign up again over and over. Try using 511.org and signup for the various programs and you'll see what bad system design is. It all works, but I have like 3 or 4 logins for each of the different sections of the site.
Anyway, I refuse to do the same thing as our venerable slicing dicing 511 site and would like to have some flexibility for future apps to use the same user database.
So I thought I had it all figured out with separate wrappers for the user database and actual "data database", but it seemed like the userdb wrapper wasn't doing too much. When I instantiated both, I figured it'd all be good, but I figured out that the userdb wasn't actually getting hit with any queries. After some mad googlin' and a huge piece of luck I stumbled upon the following needle in the proverbial haystack:
# I am trying to create two connections to the same database, but the 2nd connection doesn't work, but reuses the first connection.
This is a "feature" of PHP. When you make a 2nd connection that only differs by the database name, you get back the first connection. This is normally the reason for the problem described.
From http://php.net/manual/en/function.mysql-connect.php (this applies to other db's too):
If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.
Possible solutions include:
* Use different userid and password for each connection.
* Use different IP or host-address for each connection, even when connecting to same server! Eg. use 'localhost' and '127.0.0.l'.
* Use NConnect( ), which always forces a new connection, if the database driver supports it (Oci8, MySQL and PostgreSQL).
* Use SelectDB( ), which switches databases, if the database driver supports it (MySQL, MSSQL, Sybase).