drlhsfqoa350437979 2012-06-06 12:30
浏览 38
已采纳

Codeigniter / Active Record Class生成空白IN()

I have some code in Codeigniter that looks like this:

$this->db->select('email_account_id');
$this->db->where('TRIM(LOWER(email_account_incoming_username))',trim(strtolower($email_address)));
$query = $this->db->get($this->users_db.'email_account');

Throws this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND TRIM(LOWER(email_account_incoming_username)) = 'email@server.co.uk'' at line 3
SELECT `email_account_incoming_username`, `email_account_id` FROM (`crmuat_users`.`email_account`) WHERE `email_account_id` IN () AND TRIM(LOWER(email_account_incoming_username)) = 'email@server.co.uk'

Now I don't for the life of me understand how the "IN()" got in there?

Anybody able to see?

  • 写回答

1条回答 默认 最新

  • douxuan4556 2012-06-06 12:51
    关注

    You must have called the $this->db->where_in() method somewhere. It is impossible for CodeIgniter Active Record to generate the IN() clause unless you tell it to do so. Try to see if you called the method by accident before you do the select. Also note, that since the Active Record class has this characteristic of singularity in generating query, it is possible that you've called the method somewhere else withing another method that utilizes the Active Record class.

    For example, the following will cause the IN() clause to be generated within the final query.

    function a()
    {
        ...
        $this->db->where_in();
        ...
        $this->b();
    }
    
    function b()
    {
        // Produces the same error as stated in the question because the call of 
        // where_in() beforehand.
        $this->db->select(...)->where(...)->get(...);
    }
    

    P.S: Why are you doing trimming and converting the string into lowercase twice? It seems redundant to me.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀