Jump to content

multiple database connections


pjsteinfort

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
Link to comment
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.
Link to comment
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 :).

Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.