Welcome Guest, Not a member yet? Register   Sign In
CI4 Multiple Databases join syntax
#1

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 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB