简体   繁体   中英

"Call to undefined method CI_DB_mysqli" when executing sql join using codeigniter active record set

Following the code igniter docs when I try to execute the following sql query I get this exception? Would apprecate some help to point out the issue with the query

$query = $this->db->join('price', 'price.itemId = shop.itemId', 'right');
var_dump($query->result_array());
if ($query->num_rows() > 0){

        return $query->result();
    }

To give some background I have two tables shop and price. price table has this primary key itemId which is a foreign key in the price table. I want to get all records in the pricetable along with an attribute called name which is in the shop table

When you use the Join statement with the codeigniter query builder you must tell it with what table you want to join with.

So your code would look something like this:

$query = $this->db->join('price', 'price.itemId = shop.itemId', 'right')
             ->get('shop');

return $query->result();

Also there's no need to check if there's any rows to actually return something, just return the result like I did here, and you'll have returned an empty array. That way your function always return the same thing in this case an array.

It's not really good to return null and array in the same function.

For more information on how the query builder works here's a link to a very extensive documentation.

https://codeigniter.com/userguide3/database/query_builder.html?highlight=query%20builder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM