php - 有时但并非总是将单引号添加到 mysql 结果中

标签 php mysql codeigniter stripslashes addslashes

最初,当我尝试添加具有单引号的字符串时,数据库用于返回错误消息..

所以我在查询之前向该字符串添加了addslashes

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

enter image description here

请建议我在经历此场景后处理报价的方法

案例1:使用Addslashes

我已经有一个巨大的代码,如果我在插入之前使用addslashes,我还必须在选择查询之后使用stripslashes来删除每个结果中的\。这将导致我的 Controller 和模型在 Codeigniter 中发生大量变化。

情况2:没有addslashes

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

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

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

最佳答案

我找到了解决方案,希望这对其他人有帮助

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

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

它还支持表情符号 谢谢

关于php - 有时但并非总是将单引号添加到 mysql 结果中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21926852/

相关文章:

php - NGINX 'Access-Control-Allow-Origin' header 包含多个值

c++ - 如何序列化结构并将其存储在 MySQL 数据库中?

codeigniter - 如何在 Codeigniter 中删除浏览器输出中的前导换行符

php - 如何在 codeigniter php mysql 中创建动态数组

php - CodeIgniter:项目分页

php - Mongodb PHP驱动程序: how to create database and add user to it?

php - call_user_method_array 函数已弃用,用什么代替它?

c# - PHP 作为嵌入式脚本语言

php - SQL 类问题 - 在 null 上调用成员函数 - phpBB

php - 在 Android 中显示来自 MySQL 数据库的数据,类似于 Twitter Feed