php - Pros and cons of connecting more than one database in single script -


let's user have 2 databases hosted on single host , need connect both of them can use table anytime without adding connection code multiple times.

i have implemented in codeigniter adding authorization details of both databases in database.php file , load required database $this->load->database('dbname'); in script.

now, core php, can like:

mysql_connect ('host','user','password','port','dbname'); // connection 1 database.    

it connected first database.

now, want connect second database:

1) have not closed above connection , connected second 1

mysql_connect ('host','user','password','port','dbname1');. 

2) bad practice ? consume more objects ? should required close first 1 anyhow?

it not neccessary open 2 connection use tables 2 databases on same server. need use database.table notation. doing means can join tables different databases in same query

select t1.col1, t1.col2, t2.col2, t2.col2 db1.table1 t1 join db2.table1 t2 on t1.col1 = t2.col3 

so if have connected db1 can use db2 tables , same if connected db2 can use db1 tables.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -