我收到了这个字符串(原始复制和粘贴)
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'
从这个测试代码(在我的模型中)
$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();
为什么查询构建器会返回此查询?
我正在尝试进行此查询
SELECT `ing_names`.`name`, `ingredients`.`stock`
FROM `ingredients`
INNER JOIN `ing_names`
ON `ingredients`.`id_name` = `ing_names`.`id`
WHERE `id_type` = 1
答案 0 :(得分:1)
select should be a string or an array的第一个参数。
$this->db->select('ing_names.name, ingredients.stock');
...
//$this->db->select(['ing_names.name', 'ingredients.stock']);
select
的第二个参数指定是否转义值。