【问题标题】:Codeginter $this->db->where() function concating "IS NULL" in query automatically when using find_in_set() functionCodeigniter $this->db->where() 函数 concat "IS NULL" 在使用 find_in_set() 函数时自动查询
【发布时间】:2013-07-04 21:35:57
【问题描述】:

我正在使用FIND_IN_SET() 函数在codeigniter 中编写查询。

   $this->db->where(FIND_IN_SET('".$value."',employer_job_location));
    $query_res= $this->db->get("employer_posted_jobs");
   echo $this->db->last_query(); exit;

它正在屈服

SELECT * 
FROM (`employer_posted_jobs`) 
WHERE (FIND_IN_SET('Delhi',employer_job_location)) IS NULL

在上面的查询中,“IS NULL”是多余的,很烦人。 谁能说出为什么会出现这个查询? 谢谢。。

【问题讨论】:

  • 可以this 帮忙吗?
  • 代码很好,但我使用的是表中的列名,我无法在列名中添加转义函数

标签: codeigniter find-in-set


【解决方案1】:

您必须始终检查 FIND_IN_SET() 函数的结果以使其工作,试试这个:

$this->db->where("FIND_IN_SET('$value',employer_job_location) !=", 0);

【讨论】:

  • 感谢您的回答,但是,它使用的语法略有不同: $this->db->where(FIND_IN_SET('".$value."',employer_job_location) !=0);
  • 你总是可以做$this->db->where(sprintf("find_in_set('%d', employer_job_location) !=",$value), 0);
  • 您能否建议任何有关此的参考以深入了解它。 @MichaelK
  • @ankit suthar:您可以在此处找到 MySQL find_in_set 函数的文档:dev.mysql.com/doc/refman/5.7/en/… 其余只是 Codeigniters 查询生成器类的基本语法:codeigniter.com/user_guide/database/…
【解决方案2】:

$this->db->where("FIND_IN_SET('$value',employer_job_location) !=", 0);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    相关资源
    最近更新 更多