How to prevent single quotes when using $ this-> db-> escape in codeigniter

I have an insert in columns with single quotes. Since $this->db->query already executes the whole special character. But my problem is that I insert data such as ganesh , when the insert occurs, only ganesh is added; data after single quotes is missing. So I started using $this->db->escape , but this adds single quotes to my data that are not required, how to prevent this.

my code

 $sql="insert into tablename (list_name,list_address) values(?,?)" $res=this->db-query($sql,array($name,$add)); 

My mistake was in the front. Not the back end. I will delete the question.

+4
source share
2 answers

In the case of complex queries, it’s easier for me to simply send the raw queries as follows:

 $query = "your query"; $result = $this->db->query($query); 

Remember to remove the variables before inserting them into the query as follows:

 $var = $this->db->escape($var); 
+5
source

If you want to save data with a single quotation mark, you will need to add slashes to the data before storing them in the database as follows:

 $sql="insert into tablename (list_name,list_address) values(?,?)"; $res=this->db-query($sql,array(addslashes($name), $add)); 

then save this in your database, after that you will most likely need to use stripslashes() to remove slashes from the data before you output them to the browser.

+2
source

All Articles