Author |
Message |
Rage
Insane

Joined: Jul 30, 2004
Posts: 85
|
Posted:
Sat Sep 18, 2004 4:28 am |
|
Hi all, I'm having alot of trouble with trying to make two 7.3s use the same nuke_users table.
Here is the set of code that I've been trying to accomplish this from:
Code:$result = $db->sql_query("SELECT user_password FROM ".$user_prefix."_users WHERE user_id='$uid'");
$row = $db->sql_fetchrow($result);
$result = $db->sql_query("SELECT user_password FROM ".$dbname_2.".".$user_prefix."_users WHERE user_id='$uid'", ".$dbconnection_2.");
$result2 = $db->sql_query("SELECT points FROM ".$dbname_2.".".$user_prefix."_users WHERE user_id='uid'", $dbconnection_2);
$row = $db->sql_fetchrow($result);
|
But it does't seem to work, and I'm not 100% sure what to define in config.php (such as the second db fields etc)
Anyone have any ideas? Or new code?
Help is greatly appreciated. |
_________________ It's not that I'm afraid of dying, it's just that I don't want to be there when it happens. - Woody Allen |
|
|
 |
MrFluffy
Hangin' Around

Joined: Jun 24, 2004
Posts: 28
Location: Berlin
|
Posted:
Sat Sep 18, 2004 6:35 am |
|
I'd try to define a second set of access variables in config.php (e.g. $dbhost2, $dbuname2, $dbpass2, $dbname2) and then make a second connection in db.php, like
Code:$db_2 = new sql_db($dbhost2, $dbuname2, $dbpass2, $dbname2, false);
if(!$db_2->db_connect_id) {
die("<br><br><center><img src=images/logo.gif><br><br><b>There seems to be a problem with the MySQL server, sorry for the inconvenience.<br><br>We should be back shortly.</center></b>");
}
|
I don't know if that's sufficient, never did it before. |
_________________ cu,
MrFluffy
Only registered users can see links on this board! Get registered or login! |
|
 |
 |
Rage

|
Posted:
Sat Sep 18, 2004 6:51 am |
|
I did actually define that, but I'll try it with that new set of code added. Thanks Fluffy!
I'll give it a whirl. |
|
|
|
 |
Rage

|
Posted:
Sun Sep 19, 2004 10:23 am |
|
Nope, all I get is the site with the error SQL server message above it. |
|
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Sun Sep 19, 2004 11:05 am |
|
Just so I understand the environment you are working in, you have 2 nuke sites on the same server that you want to share the same table - correct? An they each need to connect with a table that is stored in only one of the other's? Like this?
Site A has the master users table
Site B needs to conect to Site A's user table
or are you attempting to have an independent table that is not stored in either Site A nor Site B, like this.
Independent database (IDB) on same server
Site A connects to user table in IDB
Site B connects to user table in IDB |
|
|
|
 |
Rage

|
Posted:
Sun Sep 19, 2004 1:46 pm |
|
It doesn't really matter, as long as two sites are using the same user table, so no one needs to re-register.
Whicihever way is more simple.  |
|
|
|
 |
Raven

|
Posted:
Sun Sep 19, 2004 1:52 pm |
|
It does matter as to the resolution of the issue. Are the sites using the same MySQL server? If not, then it is more difficult, if not impossible, as most sites only allow 'localhost' connections. |
|
|
|
 |
Rage

|
Posted:
Mon Sep 20, 2004 9:07 am |
|
Yes they are using the same server.  |
|
|
|
 |
Rage

|
Posted:
Tue Sep 21, 2004 3:00 pm |
|
*bump*
Any ideas from you guys? They're on the same server and can use as many dbs as needed.  |
|
|
|
 |
Holbrookau
Hangin' Around

Joined: Jun 25, 2004
Posts: 32
|
Posted:
Wed Sep 22, 2004 12:51 am |
|
Rage wrote: | Nope, all I get is the site with the error SQL server message above it. | What is the exact error message?
Something to try: Make a new Database User with the same permissions as the existing User, edit one config.php to suit. |
|
|
|
 |
Rage

|
Posted:
Wed Sep 22, 2004 8:36 am |
|
Holbrookau wrote: | Rage wrote: | Nope, all I get is the site with the error SQL server message above it. | What is the exact error message?
Something to try: Make a new Database User with the same permissions as the existing User, edit one config.php to suit. |
It's the default error in MrFluffy's code which specifies whether config and/or the sql file has been uploaded, it's in the code above.  |
|
|
|
 |
MrFluffy

|
Posted:
Wed Sep 22, 2004 8:45 am |
|
You mean
Quote: | There seems to be a problem with the MySQL server, sorry for the inconvenience. |
?
I tried the changes myself at some point and at least didn't get any error...
But I'm afraid I didn't get the other database's FAQ entries which I used for testing neither. I'll try again... |
|
|
|
 |
Rage

|
Posted:
Wed Sep 22, 2004 10:11 am |
|
Thanks alot, this can get very confusing. |
|
|
|
 |
Raven

|
Posted:
Wed Sep 22, 2004 10:25 am |
|
Raven wrote: | Just so I understand the environment you are working in, you have 2 nuke sites on the same server that you want to share the same table - correct? An they each need to connect with a table that is stored in only one of the other's? Like this?
Site A has the master users table
Site B needs to conect to Site A's user table
or are you attempting to have an independent table that is not stored in either Site A nor Site B, like this.
Independent database (IDB) on same server
Site A connects to user table in IDB
Site B connects to user table in IDB | Which situation is yours? |
|
|
|
 |
Rage

|
Posted:
Wed Sep 22, 2004 10:44 am |
|
Yes, site A and B get the table from a main 'IDB' and they're on same server.  |
|
|
|
 |
Rage

|
Posted:
Fri Sep 24, 2004 10:03 am |
|
*one last bump*
No one knows?  |
|
|
|
 |
MrFluffy

|
Posted:
Fri Sep 24, 2004 10:12 am |
|
I tried different possibilities so far. But neither with the phpBB abstraction layer nor with the old nuke sql layer I had any success. I don't get any errors though, it's just that using $db_2-> doesn't query any data from the second database (on the same server) and trying to create a second connection string like $dbi ($dbj) replaces the first one, so all queries go to the second database...
I have not completely given up yet, just a little busy with other things these days. |
|
|
|
 |
Raven

|
Posted:
Fri Sep 24, 2004 10:25 am |
|
Rage, I have been tied up. I have the solution - I just have to dig it up. It revolves around the fact that MySQL will not open up 2 different connections. You have to close the one and open the other. Then, close the second one and reopen the first. I'll try to find the code as soon as I can. |
|
|
|
 |
Rage

|
Posted:
Fri Sep 24, 2004 2:06 pm |
|
Thanks you guys, I've tried some of my solutions, but I am no whizz with SQL. |
|
|
|
 |
Rage

|
Posted:
Fri Oct 01, 2004 2:58 pm |
|
Should I give up on all hope?  |
|
|
|
 |
Raven

|
Posted:
Fri Oct 01, 2004 3:02 pm |
|
Nah. Never give up hope . |
|
|
|
 |
Raven

|
Posted:
Sat Oct 30, 2004 11:13 pm |
|
I told you not to give up
First connection use pconnect instead of connect.
Code:$db1 = mysql_pconnect($db1_host,$db1_username,$db1_dbpass) or die("Unable to pConnect to $db1_host. MySQL said ".mysql_error());
mysql_select_db($db1_dbname,$db1) or die("Unable to select pConnect database $db1_dbname . MySQL said ".mysql_error());
|
Second connection use connect instead of pconnect.
Code:$db2 = mysql_pconnect($db2_host,$db2_username,$db2_dbpass) or die("Unable to connect to $db2_host. MySQL said ".mysql_error());
mysql_select_db($db2_dbname,$db2) or die("Unable to select connect database $db2_dbname . MySQL said ".mysql_error());
|
// your code
This is of the utmost importance. Regular connection to MySQL are closed automatically when the script ends. Persistant connections remain open! If you do not explicitly close them then that connection will remain open until the MySQL server is restarted. Continually running the script will result in a server lockout with "Too Many Connections"! So, you must issue a mysql_close($db1); just before the script terminates or immediately after you are done querying the database. So, the script should look like thisCode:$db1 = mysql_pconnect($db1_host,$db1_username,$db1_dbpass) or die("Unable to pConnect to $db1_host. MySQL said ".mysql_error());
mysql_select_db($db1_dbname,$db1) or die("Unable to select pConnect database $db1_dbname . MySQL said ".mysql_error());
$db2 = mysql_pconnect($db2_host,$db2_username,$db2_dbpass) or die("Unable to connect to $db2_host. MySQL said ".mysql_error());
mysql_select_db($db2_dbname,$db2) or die("Unable to select connect database $db2_dbname . MySQL said ".mysql_error());
// Your script code
mysql_close($db1); // Must have!!!!
mysql_close($db2); // Not required but good coding practice :)
|
Let me know if this works. |
|
|
|
 |
Rage

|
Posted:
Wed Nov 03, 2004 11:13 am |
|
I love you.
I'll give it a run soon.  |
|
|
|
 |
|