1

Possible Duplicate:
How do you connect to multiple MySQL databases on a single webpage?

I am building a search engine for my website, I have 6 databases with many tables.

For multiple database I know I have to build a index file containing information from all database and tables.

I know how to build a search engine for database in PHP and MySQL,

Connect to multiple database

mysql_connect(“hostname”, “username”, “password”);
mysql_select_db(“database1”);

mysql_connect(“hostname”, “username”, “password”);
mysql_select_db(“database2”);

and query like this

"(SELECT * from database1.search_table WHERE MATCH (title, link) AGAINST(‘keyword’))
  Union All 
 (SELECT * from database2.search_table WHERE MATCH (title, link) AGAINST(‘keyword’)"

I want to do it by making an index file.

Please suggest any good tutorial or method for this, I google many times but no good results.

Community
  • 1
  • 1
  • yes then if i use UNION ALL in query, the resulting query will become too large, so i want to make a single index file which store all my databases information. how to make that index file. should i make another database containing all data from databases –  Jul 25 '12 at 06:46
  • I don't think you are able to execute a single query over multiple databases - I think you'll have to make individual queries to wach on and then combine the data yourself. – Lix Jul 25 '12 at 06:48
  • also my question is not duplicate as i am asking about making search engine not the way to connect multiple database. i know ho to connect to multiple databases. –  Jul 25 '12 at 06:49
  • What you do once you have the multiple connections is not related to this question... You need a way to connect to multiple databases - and you can find the answer in the link I posted. – Lix Jul 25 '12 at 06:50

1 Answers1

0

I think of three ways to do this: 1-st You can user multiple database connection. That's the heaviest way to do this, because it'll increase the connections to the server. 2-nd You can just switch the chosen database. 3-rd You can make your queries database independent by selecting the database in the query. Here's an example :

SELECT * FROM `database`.`table` WHERE `database`.`table`.`column`='something'

I personally think that the third way is the best.

HerpaMoTeH
  • 364
  • 3
  • 13