将单引号添加到mysql结果中,有时但不总是 [英] Adding single quote into mysql results with \'s sometimes but not always

查看:342
本文介绍了将单引号添加到mysql结果中,有时但不总是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初,当我尝试添加一个单引号数据库用于返回错误消息的字符串。



所以我添加了 addslashes 到查询之前的那个字符串。


添加addslashes后,String在DataBase中看起来像这样。
由于某种原因,不总是插入反斜杠。




请向我建议一种在处理这种情况后处理报价的方法



Case1:使用Addslashes



我已经有一个巨大的代码, addslashes ,则在选择查询后,还必须使用 stripslashes 在每个结果中删除\。这将导致我的控制器和模型IN Codeigniter 中发生很多变化。



Case2:没有addslashes >

如果我不使用addslashes或mysql_escape我的数据库不允许我存储单引号。



我将字符集更改为 utf8mb4_general_ci ,但仍然没有用。
我还确保 config.php 中的字符集也包含 utf8mb4字符集



有效的方法有什么建议吗?

解决方案

,希望这对其他人有帮助


将MySql更新为5.5.3+并使用charset utf8mb4_general_ci ..确保
数据类型是长文本


就是这样。根据我所知,不需要使用addslashes和stripslashes。



它还支持表情符号的
感谢


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?

解决方案

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

这篇关于将单引号添加到mysql结果中,有时但不总是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆