Reputation: 711
In codeigniter when i am using function $this->db->escape() while insert data, It is adding single quote in database, Can anyone please help why i am getting this issue ?
Here is my code
$data = array('company_id'=>$this->db->escape($companyID),'payor_type'=>$this->db->escape($payor_type),
'payer_type'=>$this->db->escape($payer_type),'insurance'=>$this->db->escape($insurance),
'created_date'=>date("Y-m-d H:i:s"));
$this->db->insert('tb_Payer',$data);
Upvotes: 2
Views: 16183
Reputation: 865
If you are using $this->db->insert, you don't need $this->db->escape because $this->db->insert is already escaping the data for you. That's why you are getting quotes. You are escaping data that was already escaped.
Upvotes: 0
Reputation: 769
When you use the query builder class to construct your queries the values are escaped automatically by the system so you don't have to use the function $this->db->escape
. In your case, each value was escaped by the escape function and the system did it again for each value when executing the insert function.
Now if you want to run custom queries using the function $this-db->query
it is a good practice to escape the data like bellow:
$sql = "INSERT INTO table (column) VALUES(".$this->db->escape($value).")";
$this->db->query($sql);
Upvotes: 8