简体   繁体   中英

Why Codeigniter's Query Builder is returning this MySQL query wrong and twice?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM