Welcome Guest, Not a member yet? Register   Sign In
Multiple Database problem
#1

[eluser]Unknown[/eluser]
Hi all

i have problem on using multiple database

example:
Using 2 databases named DB1 and DB2

In DB1,
Table samples: primary key productno
Table order: primary key productno

In DB2,
Table product: primary key productno

i like to get the result of joining these 2 databases DB1 & DB2

i write a simple query for joining

select * from DB1.sample A,DB2.product B where DB1.sample.productno=DB2.sample.productno

when i execute this query, it is working fine.

but i doesn't want to mention the database name in query. because anytime i will change the database names.

so without using Database name, how we can join these two databases in CI

can any one help me
thanks
#2

[eluser]rogierb[/eluser]
You need the database names. Why not pluck them them out of your database config?

Code:
qry =  "select * from ".$db['default']['database'].".sample A,".$db['second']['database'].".product B where ".$db['default']['database'].".sample.productno=".$db['second']['database'].".sample.productno




Theme © iAndrew 2016 - Forum software by © MyBB