gpt4 book ai didi

php - 根据列的字符串长度从 MySQL 中进行选择 - CodeIgniter

转载 作者:行者123 更新时间:2023-11-29 23:52:06 24 4
gpt4 key购买 nike

我正在使用 CodeIgniter 根据 1 列的字符串长度是否大于 1 来从 MySQL 表中选择数据。

代码:

        $this->db->order_by('time_stamp', 'desc');
$this->db->where('strlen(user_categrory)>1');//I know this code does not work but that's what I wanted to achieve
$data['record']=$this->db->select('username, user_category, email, source, status, test_group, time_stamp, referrer_email')->get('user');

关于如何完成这项工作有什么建议吗?非常感谢。

最佳答案

将 false 作为 where() 的第三个参数传递,CodeIgnite 不会转义第一个参数中的字符串 https://ellislab.com/codeigniter/user-guide/database/active_record.html#select 。然后您可以使用 MySQL 的 LENGTH() 函数:

$this->db->where('LENGTH(user_categrory)>1', null, false);

此外,您可能需要使用 CHAR_LENGTH() 而不是 LENGTH(),因为 LENGTH() 以字节为单位,而 CHAR_LENGTH() 是以实际字符为单位。

关于php - 根据列的字符串长度从 MySQL 中进行选择 - CodeIgniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25578824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com