Welcome Guest, Not a member yet? Register   Sign In
JOIN tables from different databases (same server) - c14
#1

Hi all,
Using Ci4, I have a need to run a query on two tables in different databases (table1 on db1, table2 on db2). I have 2 connections configured & working fine for everything else in //Config/Database (con1, con2).
I need to run a query something like this, where connection (con1) connects to db1:
PHP Code:
public function getEmpsPlusUsers () {
     $this->db db_connect('con1'); //THIS IS DB1
 
     $sql=("SELECT e.emp_no, e.email, u.email FROM table1 e LEFT JOIN table2 u ON e.email=u.email");
     try {
         $query $this->db->query($sql);
         $row $query->getResultArray();
         }catch(\Exception $e) {
         print_r($e);
         die();
     }
 } 

But of couse this throws a error as I do NOT have permission to access db2 becuase I have NOT established a connection!!
Any ideas anyone ???
Reply


Messages In This Thread
JOIN tables from different databases (same server) - c14 - by 68thorby68 - 07-11-2022, 03:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB