I am working on a existing project whose code is written by earlier developer. When I read a function in the model it was written:
$this->db->select('1', FALSE);
$this->db->where('product_id', $product_id);
$query = $this->db->get('product');
if ($query->num_rows() == 1) {
return false;
}
return true;
I am wondering what does this first statement does? i.e $this->db->select('1', FALSE); because there is no column named 1 in the product table. I searched online but there is no help. Would any explain?
As I haven't seen anything like that so far, I would do a
echo $this->db->last_query()
after the $this->db->get()
just to see the actual sql query for that.
SELECT 1 FROM
It is used to determine the existence of a result. It will return a column of 1's for every row in the result.
SELECT 1;
=> 1
SELECT 1 + 1;
=> 2
Codeigniter you can use this query when
$this->db->select('1', FALSE);
If you don't turn it to FALSE, you can only select columns
$this->db->select('column', TRUE);