duanen19871021
duanen19871021
2017-11-08 02:54

为什么Codeigniter的Query Builder会错误地返回这个MySQL查询并且两次?

已采纳

I'm getting this string (raw copy and paste)

SELECT `ing_names`.`name` FROM `ingredients` INNER JOIN `ing_names` ON `ingredients`.`id_name` = `ing_names`.`id` WHERE `id_type` = '1'
SELECT `ing_names`.`name` FROM `ingredients` INNER JOIN `ing_names` ON `ingredients`.`id_name` = `ing_names`.`id` WHERE `id_type` = '1'

From this test code (in my model)

    $this->db->select('ing_names.name','ingredients.stock');
    $this->db->from('ingredients');
    $this->db->join('ing_names','ingredients.id_name = ing_names.id', 'inner');
    $this->db->where('id_type','1');

    $this->db->get();
    echo $this->db->last_query();

Why is query builder returning this query?

I'm trying to do this query

SELECT `ing_names`.`name`, `ingredients`.`stock`                    
FROM `ingredients`                                                     
INNER JOIN `ing_names`                                                   
ON `ingredients`.`id_name` = `ing_names`.`id`                      
WHERE `id_type` = 1
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongliyan9190 dongliyan9190 4年前

    First argument to select should be a string or an array.

    $this->db->select('ing_names.name, ingredients.stock');
    ...
    
    
    //$this->db->select(['ing_names.name', 'ingredients.stock']);
    

    Second argument to select specifies whether to escape values or not.

    点赞 评论 复制链接分享