Page 1 of 1

Connecting two different databases

Posted: Mon Aug 08, 2005 10:53 pm
by ija
Hi,
I developed a system which use two different databases : for login database(epantau) and for system database(upentrg).
I have problem to connect both database when developing the system.
Both database cannot integrate each other.

TQ

Posted: Mon Aug 08, 2005 11:06 pm
by nielsene
Can you explain your problem any more?

I wouldn't normally advise spliting an application across two databases, except if its a legacy system.

However, I know that MySQL, at least, allows cross database queries, so it shouldn't be too much of a problem.

You will have to be careful and explicit about the database connection parameter to the mysql_query type calls and not let PHP use its default "last used connection"

Database Conflict??

Posted: Mon Aug 08, 2005 11:44 pm
by ija
Heya Nielsene,
OK, here's how it works - one database is for security -in which it contains all the relevant info about userid +password. I named it epantau. The other database is a working database which contains vital info about my system. I called it UPENTrg.

The idea is that to disallow users from successfully bypassing the system by simply keying in the URL name in the URL browser. Instead, every time user keyed in the (direct) address in the URL browser, my login page will appear and user had to fill in the userid and password fields. So only authorised users will have access to my system.

It seems to work in a sense that whenever I initiate the bypass test, my login page appears and I had to duly key in the id plus password, and I can only access the system after verfication. However, from that page, whenever i tried to further access the system only a blank page will appear. I suspect that this is where the mess starts - coz this is where my system will call for my other database(the working database, the life n blood of the system...grrrr). Is there a conflict when I set my system this way ?
Thanks to help...

Posted: Mon Aug 08, 2005 11:48 pm
by nielsene
Hmm... Its not the way I would do it, but it should work. Do you have PHP error reporting turned on? do you have "or die(mysql_error())" after most of your database commands?

Posted: Tue Aug 09, 2005 3:05 am
by CoderGoblin
In general connecting to two databases is not normally a problem providing you open two connections, one to each database (at least this is the case with Postgres). What you need to do is ensure any commands you send to a databse point to the right connection.

Posted: Tue Aug 09, 2005 7:03 am
by Ashiro
It's not necessary to have your user data and working data on two seperate databases. I know of no known PHP application that does this. You can have the same behaviour you mention with a simple 'auth' chekc at the top of every page you have and handling of session data, etc.

Posted: Sat Aug 13, 2005 9:18 pm
by nielsene
Well it does commonly happen if you're integrating several third party applications into one application. Depending on their suuport/options for table prefixes, shared databases, schemas, etc at times you are forced to have a portal-style application that hits several different databases. In a lot of these cases I've seen people hack up a central authentication DB that they then use for everything (often merely setting all the appropriate cookies for the different apps on login, etc)

Its not a nice solution, but it is fairly common. Now I'm less sure as to why a person would design a system like that from the start....