【问题标题】:php codeigniter active records replace functionphp codeigniter 活动记录替换功能
【发布时间】:2013-12-08 04:21:26
【问题描述】:

我想在使用 codeigniter 的 mysql 查询中使用替换功能,但卡住了它不工作

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 子句”中的未知列“A3Cabriolet”

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

文件名:C:\wamp\www\system\database\DB_driver.php 行号:330"

【问题讨论】:

    标签: php mysql codeigniter function replace


    【解决方案1】:

    尝试用这样的逗号来包装您的查询

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

    还有,当你运行一次查询时,你为什么需要这个

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

    【讨论】:

      【解决方案2】:

      语法错误:您缺少“。”在 $make_name 之前应该是

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

      【讨论】:

        【解决方案3】:

        您还可以使用 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;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-06-14
          • 2014-02-22
          • 1970-01-01
          • 1970-01-01
          • 2014-10-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多