UBB.Dev
Posted By: s4dreamer Accessing a second database and UBBThreads - 07/08/2003 11:53 AM
I have a wierd problem which has just started since our admin upgraded our server.

Current s/w versions are UBB6.2.3, PHP 4.3.1, MySQL 3.23.49, Apache 1.3.27

I have written a package which uses the UBB user-id for the username. So, the first thing I do is to check the UBB authentication of the user:
Code
 <br />require ("/blah/ubbthreads/main.inc.php"); <br />require ("/blah/ubbthreads/languages/${$config['cookieprefix']."w3t_language"}/ubbthreads.php"); <br /> <br />$userob = new user; <br />$user = $userob -> authenticate("U_Username,U_PicturePosts,U_ShowSigs,U_Email,U_PictureView, <br />U_Status,U_Privates,U_Name,U_Title,U_Totalposts,U_Visible, U_Laston,U_Language,U_TimeOffset, <br />U_Groups,U_Picture,U_Number"); <br /> <br />$html = new html; <br />


Once this is done, I load my code and login to the db with a separate user and select my database:
Code
 <br />require_once("mycode.php"); <br /> <br />$db = mysql_connect("localhost", $dbuser, $dbpass); <br />mysql_select_db("mydb", $db); <br />


Now, the problem is that when the UBB authenticate() function is called, it makes a query on the database. However, the db query fails because it appears to be attempting to access "mydb.xxxxx" (sorry, can't recall the table name off-hand). The issue is that is appears to be trying to use mydb rather than the UBB database - even though the mysql_select_db() has not yet been run to connect to mydb.

From what I can tell from the PHP/MySQL status, there is a single persistent connection to MySQL, which I assume belongs to UBB.

This all worked fine before the upgrade, but I can't think for the life of me why it is failing now.

Anyone got any ideas of why it is failing or things I might try ?
I think I should add that UBB works fine on its own.
Ah, I now have the answer to this problem.

The sysadmin had given the UBBThreads db the same login id and password as my database, so they had ended up sharing the connection which became a problem when my code selected a different database.

Fixed by adding an extra parameter to mysql_connect in my code:

$db = mysql_connect("localhost", $dbuser, $dbpass, true);
© UBB.Developers