MyBB Community Forums

Full Version: Ajax Counter & 2 DB's
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a problem with my Ajax Chat Online Counter.

Due to my hosts terms & conditions i have host my Ajax Chat rooms DB tables away from where my forum and forum DB is hosted, its not a problem but the online counter that tells users how many are in chat now don't work as it s trying to look for the ajax chat tables in the forums DB.

What im looking for is a way of defining another set of DB details to where i can point my counter to the correct DB, and in the code i would change $db to $db1 or similar.

I have seen away on here before but after 2hours of searching i can't find it.

Does anyone have any ideas to how i could achieve this?

Cheers
Just make a 2nd copy of the DatabaseEngine object, and connect it to the other server, ie
$db2 = new databaseEngine;
$db2->connect('hostname', 'username', 'password');
$db2->select_db('database');
Hi

Thank you for reply, sorry my skills regarding dynamic programing are limited, where do i place the above code and how do i make a 2nd copy of the DBengine? i can't even find the file that defines $db

Cheers
The above code creates a second copy of the databaseEngine class.
If you're running under MyBB, the necessary files should already be include'd for you.

If you're unsure about how the above code works, however, I'd suggest trying to get a little more familiar of how MyBB and PHP classes work, otherwise, you're just going get hit by more problems.

Best of luck!
what i mean is which file do i insert that code into??
I really don't know, since all you really asked was how to create a 2nd DB connection...

Unfortunately, I can't write the whole thing for you. I can give pointers, however, you'll have to do the work.
The above code creates a 2nd DB connection, and you can use the $db2 object like the $db object. That's about all I can help with.
oh ok, thanks anyway, i wasn't looking for the whole thing written as i can link your code to new code i have done in config.php, ill have a play two see where your code goes.

Thank you!
You don't have the use config.php.

In the above example, just replace hostname, username, password and database with the appropriate values.
oh so change ie for user name i would put my DB user name?

Didn't think they worked like that!
Just done this now thank you,

If anyone else needs it just put Zingas Code above the Ajax countet code in global.php making sure you chang $db in the counter code to $db2

Once agian thank you!