// Join Multiple Tables from Multiple Databases in PHP
PS: You just you use the default database connection to execute the query or you can used either of any database connection if you have already made any other database connection instance.
// This is for default database connection.
$sqlStr = "SELECT d1t1.id, t1.name, d2t2.no_of_sales, d3t2.customer_type
FROM db1.Table1 as d1t1, db2.Table1 as d2t1, db3.Table2 as d3t2
WHERE d1t1.id='3' AND d3t2.customer_type='sales'";
$result = mysql_query($sqlStr);
while($row = mysql_fetch_array($result)) {
echo $id = $row['id'];
echo '\n';
echo $name = $row['name'];
..........
}
|
In the case of CodeIgniter, please find code below to pull the data from two or multiple database tables.
PS: You just you use the default ($this->db) database connection to execute the query or you can used either of any database connection if you have already made any other database connection instance.
PS: You just you use the default ($this->db) database connection to execute the query or you can used either of any database connection if you have already made any other database connection instance.
|