gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:39:10 27 4
gpt4 key购买 nike

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

所以我在查询之前向该字符串添加了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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com