Jump to content

Archived

This topic is now archived and is closed to further replies.

pjsteinfort

multiple database connections

Recommended Posts

Hi guys

Im setting up a website which uses a few opensource programs to run different parts of the website, and memberships are all integrated using amember.

I want to set up a module (in php) which links the contributions of individual members, so that if displaying the user's forum post or directory listing, we can link to other items on the site by that user - so pic posts, blogs, etc. Im assuming the best way to do this is to create multiple database connections, and have the username as the common link between all of them to find other contributions by that user

MY QUESTION IS:
Is it possible to create multiple db connections on one page? and if you can, does this then slow down the load time for that page?

If anyone knows a better way to do what im trying to do, PLEASE let me know!!!

pj

Share this post


Link to post
Share on other sites
[!--quoteo(post=363486:date=Apr 10 2006, 06:23 PM:name=pjsteinfort)--][div class=\'quotetop\']QUOTE(pjsteinfort @ Apr 10 2006, 06:23 PM) [snapback]363486[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi guys

Im setting up a website which uses a few opensource programs to run different parts of the website, and memberships are all integrated using amember.

I want to set up a module (in php) which links the contributions of individual members, so that if displaying the user's forum post or directory listing, we can link to other items on the site by that user - so pic posts, blogs, etc. Im assuming the best way to do this is to create multiple database connections, and have the username as the common link between all of them to find other contributions by that user

MY QUESTION IS:
Is it possible to create multiple db connections on one page? and if you can, does this then slow down the load time for that page?

If anyone knows a better way to do what im trying to do, PLEASE let me know!!!

pj
[/quote]

Im not sure is i understand your question 100%, but why not just use one database? there is no limit to how many tables you can have. If you need multiple databases you can do that if you want to.

Share this post


Link to post
Share on other sites
You only need to make 1 connection to the MySQL host, then you can switch between each db by using mysql_select_db().

[a href=\"http://php.net/mysql_select_db\" target=\"_blank\"]http://php.net/mysql_select_db[/a]

An example:
[code]<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if(!$link)
{
    die('Not connected : ' . mysql_error());
}

$db_selected = mysql_select_db('foo', $link);

if($db_selected)
{
    // do all the queries you need from the foo database

}else{
    die ('Can\'t use foo : ' . mysql_error());
}

$db_selected = mysql_select_db('bar', $link);

if($db_selected)
{
    // do all the queries you need from the bar database    
}else{
    die ('Can\'t use bar : ' . mysql_error());

}

mysql_close($link);

?>[/code]

HTH :).

Share this post


Link to post
Share on other sites
Im working on a guess here, but I bet you could really use this:

[a href=\"http://www.webyog.com/sqlyog/index_sqlyogfree.php\" target=\"_blank\"]http://www.webyog.com/sqlyog/index_sqlyogfree.php[/a]

download it and you can connect to your mysql though a GUI. Its exteremly usefull and free.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.