Welcome Guest, Not a member yet? Register   Sign In
Best way to get just a tiny bit of data from another database

Hey all,

I'm working on a new website (my second in CI ^^), but I've stumbled upon a problem:

The site has a phpbb3 forum and people who comment on the site announcements or blog entries can enter their forums password, that way their avatar gets shown etc.

This is the only time I need to connect to another database. What would be a good coding approach to this?

Thanks for your thoughts and time!

Okay, after reading the user guide, I decided to use this approach to connect to the phpbb3 database:

$dsn = 'mysql://username:[email protected]/db';
$phpbb = $this->load->database($dsn, true);
then I can use it in my code snippet. However, I would like to disconnect from the database when I've finished with it, seems like unnecessary resources to me to keep a second db connection open. But I couldn't find this in the user guide, so my final question is: how would I disconnect from $phpbb then? Just use mysql_close() ?

[eluser]Jeff Logan[/eluser]
You can use mysql_close(), although non-persistent open links are automatically closed at the end of the script's execution so it is not necessary (although good coding practice - expecially if you are using a mixture of non-persistent and persistent connections in your code).

You can also specify which connection to close, otherwise it closes the last connection made.

mysql_close ([ resource $link_identifier ] )

Hope the above helps.

Yeah, that's directly from the php.net documentation, but how do I get $link_identifier? It can't be just $phpbb (as in my example) seeing as that's an object...

Meh, I'll go through the library and hope to find it.

I think the way to go (least how I've got it working) for a one-time call to a second db is:

Set up second DB config array in database config file.

$config['newdb']['hostname'] ....

Set pconnect to FALSE

Create object for other DB: $NEWDB = $this->load->database('newdb');

Now you can grab something from your other DB and CI will go back to your primary DB when you're done.

See manual: database config, connecting to multiple databases for more info.

Theme © iAndrew 2016 - Forum software by © MyBB