I am having problems in fetching data from my database here is my getOne function
public function getOne($sku)
{
$ans = 0;
$query = $this->db->query('SELECT * FROM barcode_sku WHERE sku = "$sku"');
$res = $query->result();
$row = $res[0];
$ans = $row->quantity;
return $ans;
}
the variable $sku will have values like bc_001 or bc_002.... The problem is if I hard code this value i.e bc_001 in my query it fetches the result correctly however when I use the variable $sku in my query it does not work.
return $this->db->get_where('barcode_sku', ['sku' => $sku])->row('quantity');