[英]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. 由于某些原因,反斜杠并非总是插入。
Please suggest me a method for handling quotes after going through this scenario 请通过这种情况向我建议一种处理报价的方法
Case1: Using Addslashes 情况1:使用加号
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. 我已经有一个庞大的代码,其中,如果我在插入之前使用和addslashes,我还必须用stripslashes选择查询后删除\\在每一个结果。 This will result lot of changes in my controllers and models IN Codeigniter . 这将导致我在Codeigniter中的控制器和模型发生很多变化。
Case2: Without addslashes 情况2:不带斜线
If i dont use addslashes or mysql_escape my database doesnot allow me to store single quotes. 如果我不使用addlashes或mysql_escape,我的数据库将不允许我存储单引号。
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 . 我将字符集更改为utf8mb4_general_ci ,但仍然没有用..我还确保config.php中的字符集也包含utf8mb4字符集 。
Any suggestions for an efficient method? 对有效方法有何建议?
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 将MySql更新到5.5.3+,并使用字符集utf8mb4_general_ci。确保数据类型为longtext
That's it. 而已。 No need of using addslashes and stripslashes as far as i know. 据我所知,不需要使用addslashes和stripslashes。
It also supports emoji's Thanks 它还支持表情符号的感谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.