简体   繁体   English

使用 codeigniter 活动记录集执行 sql 连接时“调用未定义的方法 CI_DB_mysqli”

[英]"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?按照代码点火器文档,当我尝试执行以下 sql 查询时,我得到了这个异常? 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.为了提供一些背景信息,我有两个表 shop 和 price。 price table has this primary key itemId which is a foreign key in the price table.价格表有这个主键 itemId,它是价格表中的外键。 I want to get all records in the pricetable along with an attribute called name which is in the shop table我想获取价格表中的所有记录以及商店表中名为 name 的属性

When you use the Join statement with the codeigniter query builder you must tell it with what table you want to join with.当您将 Join 语句与 codeigniter 查询构建器一起使用时,您必须告诉它您要连接哪个表。

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.这样你的 function 在这种情况下总是返回相同的东西一个数组。

It's not really good to return null and array in the same function.在同一个function中返回null和array真的不太好。

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 https://codeigniter.com/userguide3/database/query_builder.html?highlight=query%20builder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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