Connecting to 2 databases

Codes here !

Moderators: macek, egami, gesf

pilchard
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 07, 2003 7:58 am
Location: UK

Connecting to 2 databases

Postby pilchard » Mon Jul 07, 2003 8:31 am

I have an application which authenticates with one database using some third-party code over which I have no control, but then uses a second database for its own data.

This had been working fine, but some recent changes on the server have caused the authentication code to start to fail.

The code looks something like this:
<?
require("user.php"); // Third-party code
$user = new User;
$user->authenticate();

$db = mysql_connect("localhost", "me", "mypass");
mysql_use_db("mydb", $db);

// Do the work
?>

I believe (although I am not 100% certain) that the third-party code maintains a persistent db connection.

Anyway, what's happening now is that when $user->authenticate() is called, the db query it uses errors out saying it can't find the table mydb.users. Note that "mydb" is my database name, and definitely not its db name.

This problem used to happen the reverse way around, which is why I use the $db in there now, but it puzzles me greatly that the authentication code fails when the mysql_use_db call for my code hasn't even been executed yet.

Does anyone have any ideas about why this problem might be coming up ?

Thanks, Trev

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Mon Jul 07, 2003 8:54 am

when you say mysql_use_db() ... do you mean mysql_select_db() ??

also can you manually verify that the users table exists inside your mysql database?

if the 3rd party code maintains a p connection it still should not cause errors since you are using different resource identifiers for the connections.

pilchard
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 07, 2003 7:58 am
Location: UK

Postby pilchard » Mon Jul 07, 2003 11:08 pm

Yeah, sorry, I did mean mysql_select_db() - I was going from memory.

The table does exist because the third-party application uses it too.

I'm just really puzzled as to why the authenticate actually tries to use my database when we haven't even reached that part of the code which logs in and selects my db.

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Tue Jul 08, 2003 6:30 am

Can you post some more code?,
the User class template for example and anything else that take part in the process.

pilchard
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 07, 2003 7:58 am
Location: UK

Re: further information on database error

Postby pilchard » Tue Jul 08, 2003 7:00 am

Sorry, I don't have the code for the other package - it's installed on a system to which I don't have direct access, and the sysadmin has, as yet, not responded to my request for access to the code.

I can tell you, though, that it's UBBThreads, from Infopop.

As far as I can tell, the authenticate() function queries cookies from the user's browser and uses those to establish whether or not the user is logged in, what forums have been visited etc. During this function it queries the database, which is where I see the failure.

Sorry I'm not able to give more information - I guess I was just hoping someone would recognise the symptom and say "oh, yes - change x to y" :(

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Tue Jul 08, 2003 7:33 am

Which changes were made with the server??
That is the key.

pilchard
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 07, 2003 7:58 am
Location: UK

Postby pilchard » Tue Jul 08, 2003 8:09 am

Yeah, you're right, that is the key.

Unfortunately, the change was a complete install of everything on a new box because the old one went belly-up :(

I don't have a record of s/w versions installed before the change, and neither does the guy who administers the box, so I'm pretty much stuffed.

Guess I'm just going to have to experiment with the code I have to see if I can stop it from faulting. I'll also pursue getting access to the third-party source to see if I can see anything obvious there.

Thanks anyway, Joan :)[/b]

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Jul 08, 2003 9:42 pm

PEOPLE ARE YOU CRAZY!

please never forgot about mysql_error()!

pilchard
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 07, 2003 7:58 am
Location: UK

Postby pilchard » Tue Jul 08, 2003 10:54 pm

I use mysql_error(), I just left it out of the example code to make it easier to read, but thanks anyway for the reminder :)

pilchard
New php-forum User
New php-forum User
Posts: 6
Joined: Mon Jul 07, 2003 7:58 am
Location: UK

Discovered the fault!

Postby pilchard » Wed Jul 09, 2003 7:29 am

I just thought I'd let you all know that I discovered the fault.

The sysadmin had given my database the same login id and password as that of the third party app, so they were ending up sharing the db connection.

Thus, when my code selected a different db, the UBBThreads code inherited this and ended up trying to access the wrong thing.

I have corrected the fault by adding an extra parameter to the mysql_connect code in my PHP:

$db = mysql_connect("localhost", "me", "mypass", true);

Thanks to all who looked/thought about this and those who replied.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest