phpmysqlcodeigniterstripslashesaddslashes

Adding single quote into mysql results with \'s sometimes but not always


Initially when i try to add a string that have Single quotations the database used to return an error message..

So i added addslashes to that string before the query.

After adding the addslashes, the String looks like this in DataBase. For some reason the backslashes are not always inserted.

enter image description here

Please suggest me a method for handling quotes after going through this scenario

Case1: Using Addslashes

I already have a huge code, where if i use addslashes before insertion, i must also use stripslashes after select query to remove \ in every result. This will result lot of changes in my controllers and models IN Codeigniter.

Case2: Without addslashes

If i dont use addslashes or mysql_escape my database doesnot allow me to store single quotes.

I changed the charset to utf8mb4_general_ci, but still of no use.. I also made sure that the charset in config.php also contains utf8mb4 charset.

Any suggestions for an efficient method?


Solution

  • I found the solution, hope this will be helpful to others

    Update MySql to 5.5.3+ and use charset utf8mb4_general_ci.. Make sure that the datatype is longtext

    That's it. No need of using addslashes and stripslashes as far as i know.

    It also supports emoji's Thanks