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

情到浓时终转凉″ 提交于 2019-12-11 19:33:17

问题


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.

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?


回答1:


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



来源:https://stackoverflow.com/questions/21926852/adding-single-quote-into-mysql-results-with-s-sometimes-but-not-always

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!