php代码点火器活动记录替换功能


php codeigniter active records replace function

我想使用codeigniter在mysql查询中使用replace函数,但它的无法工作

function getmakeid($make_name)
{
    $content_query = $this->db->query("select Make_ID from make where LOWER(REPLACE(Make_name, ' ', '')) = ".$make_name);
    $content_query = $this->db->get();
    if($content_query->num_rows() > 0)
    {
        return $content_query->result();
    }else{
        return false;
    }
}

返回错误

错误编号:1054

"where clause"中的未知列"A3Cabriolet"

select
  model_id
from model
where LOWER(REPLACE(model_name, ' ', '')) = A3Cabriolet

文件名:C:''wamp''www''system''database''DB_driver.php线路编号:330"

尝试用逗号包装您的查询,如以下

$query  =   "SELECT
              Make_ID
            FROM make
            WHERE LOWER(REPLACE(Make_name, ' ', '')) = "."'"$make_name."'";
$content_query = $this->db->query($query);  

此外,当你已经运行了一次查询,为什么你需要这个

$content_query = $this->db->get();

语法错误:$make_name之前缺少一个"."应该是

$query  =   "SELECT
              Make_ID
            FROM make
            WHERE LOWER(REPLACE(Make_name, ' ', '')) = '" . $make_name . "'";
$content_query = $this->db->query($query); 

您还可以使用活动记录,imo是最佳选项。

$this->db->select('Make_ID')->
           from('make')->
           where("LOWER(REPLACE(Make_name,' ',''))",$make_name,TRUE);
$query = $this->db->get();
if($query->num_row() >= 1) {
    return $query->result();
}else {
    return TRUE;
}