Jump to content


Photo

multiple database connections


  • Please log in to reply
3 replies to this topic

#1 pjsteinfort

pjsteinfort
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 10 April 2006 - 11:23 PM

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

#2 sdaniels

sdaniels
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 10 April 2006 - 11:43 PM

[!--quoteo(post=363486:date=Apr 10 2006, 06:23 PM:name=pjsteinfort)--][div class=\'quotetop\']QUOTE(pjsteinfort @ Apr 10 2006, 06:23 PM) View Post[/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.


#3 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 10 April 2006 - 11:48 PM

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:
<?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);

?>

HTH :).



#4 sdaniels

sdaniels
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 10 April 2006 - 11:54 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users