【发布时间】:2018-04-10 16:57:18
【问题描述】:
我已尝试使用此代码计算行数
$count = $this->db->query("select count(*) from cgdict where cg like '%".$search_data."%'");
echo $count;
它给了我一个错误
Object of class CI_DB_mysqli_result could not be converted to string
【问题讨论】:
-
你想要那个 SQL 注入,是吗?
-
您应该使用
$row = $this->db->query(...)->row()anf 然后$count=$row->count您直接将结果对象分配给字段 -
您的查询没问题。但是
echo $count是错误的。因为 echo 打印出一个字符串。但是$count不是字符串。它的对象。尝试使用 print_r 或 var_dump 来查看 $count 是什么。
标签: php codeigniter activerecord count