在codeigniter where子句中添加子字符串

v2g6jxz6  于 2021-06-21  发布在  Mysql
关注(0)|答案(2)|浏览(305)

是否可以在活动查询中添加子字符串?
我有一个用纯sql编写的例子。但是,当我在ci中的活动查询中编写它时,结果不会显示。我想知道是否有人可以帮助验证这是否正确。

$this->db->distinct();
        $this->db->select('user_table.id','user_table.first_name','user_table.last_name','user_table.email','user_table.created_on');
        $this->db->from($this->user_table);
        $this->db->join($this->account_items_table,'user_accounts.id = account_items.user_id','LEFT');
        $this->db->where('SUBSTRING(account_items.key,1,2)',$input);
bqjvbblv

bqjvbblv1#

这对我来说很好:

$this->db->where('SUBSTRING(title, 1, 1)=','H');
$query = $this->db->get('news');
print $this->db->last_query();

我能看到的唯一区别是我包含了=操作符。
如您所见,它返回名为“hello”的文章:https://mi-linux.wlv.ac.uk/~in9352/codeigniter3/
sql语句是:select*from news 其中substring(title,1,1)='h'
建议您使用

print $this->db->last_query();

要查看sql是什么。。。在我的情况下,它可以发现丢失的=运算符。。。调试总是有用的!

igetnqfo

igetnqfo2#

可能ci在表达式周围添加了反勾号,而pass中的第三个参数为false where() ```
$this->db->where('SUBSTRING(account_items.key,1,2)',$input,false);

相关问题