Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

Two db connect files

1

56 views

I am using one db file to connect to the database. However, i need to show something else from another db database on this site. I can't use two db connect files. So, how do i go about display one websites content on another website with two different connections.

asked February 21, 2011 5:39 pm CST
AAA
posted via StackOverflow

2 Answers

3
 

For one thing, you don't need separate database connections to the same server. Simply specify the database name before each table name in your SQL statements. For example:

SELECT foo, bar FROM db.table;

rather than:

SELECT foo, bar FROM table;

For another, you shouldn't be storing the database connection in a global for just the sort of reason you're running into. I suspect you're using the outdated mysql extension, which uses an implicit DB connection resource whenever one isn't explicit. Switch to PDO and create a simple connection manager class. One big advantage to PDO is it supports prepared statements, which can be safer and more performant than what the mysql extension provides. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO"

answered February 21, 2011 6:23 pm CST
1
 

If it is a separate db server you might need to look into the mysql federated engine which allows you to link to databases on separate servers as if they were on the same host.

answered February 21, 2011 6:23 pm CST

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions
Connect to SQL databse
February 3, 2011
Connect to mysql
December 26, 2010
Filezilla won't connect
January 17, 2011
Connect to url in python
January 16, 2011
Mysql connect Error
February 14, 2011