CodeIgniter Forums
CI4 Multiple Databases join syntax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: CI4 Multiple Databases join syntax (/showthread.php?tid=89147)



CI4 Multiple Databases join syntax - dougwolf - 01-16-2024

I have a project where I need to join two tables from different databases. I have seen other threads on this but they always assume the full text name of the second database. My databases are configured in the .env file, then instantiated. My code is as follows. What is wrong with my syntax?  I am getting the famous:
 "Object of class CodeIgniter\Database\MySQLi\Connection could not be converted to string" error.
Code:
    /**
    * DashModel constructor.
    */
    public function __construct()
    {
        parent::__construct();
        $this->db = \Config\Database::connect('default');
        $this->www = \Config\Database::connect('www');
        $this->data = \Config\Database::connect('data');
    }

    /**
    * @return int
    */
    public function getCirculUsersCount()
    {
        $mydata = array();
        $sql = "SELECT distinct o.patient_id FROM observations o
                JOIN($this->www->table('patients as p'), p.id=o.patient_id)
                WHERE o.observations_devices_id='6'";
        $query = $this->data->query($sql);
        $mydata = $query->getResultArray();
        return count($mydata);
    }

I get