gpt4 book ai didi

php - 使用 php 和 MySql 处理单引号和双引号插入问题的简单有效方法是什么

转载 作者:太空宇宙 更新时间:2023-11-03 12:14:07 25 4
gpt4 key购买 nike

<分区>

我主要使用 Php 5.4+ 和 MySql 5.5+ 版本。我正在为所有项目使用 Codeigniter

我遇到的问题是

Sometimes(on some production servers) when ever a POST variable contains ' or " quotes, a Database error occurs. But few times(on other servers) they work properly, i mean the quotations get inserted into tables

虽然 php 和 CI 有很好的工具来处理这些字符串,包括 addslashesmysql_escape_sequence

  1. It is not that easy to check these conditions for every possible variable that is being posted by the User

  2. Every time we have to use addslashes Ex: It\'s and while giving the output we have to again apply stripslashes to output It's. But it is difficult to handle for large values.

  3. As the Database saves the data as It\'s it is difficult to search for these strings.

经过几天的努力,我发现使用 utf8mb4_general_ci 优于 utf8

因此,我确保 CI 的 Database.php 具有以下内容

    $db['default']['char_set'] = 'utf8mb4';
$db['default']['dbcollat'] = 'utf8mb4_unicode_ci';

另外,我将各个列的数据类型更改为“LONGTEXT”,并将其排序规则更改为“utf8mb4_general_ci

令我惊讶的是,它们适用于某些服务器。

But Still on some servers i found the same problem. which is bit frustrating even though i made sure the server configuration matches with those working servers.

所有 php 和 mysql 开发人员如何处理此场景?您采取了哪些预防措施?

请推荐!!

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