自动转义查询中的数据

发布于 2024-12-10 20:18:40 字数 141 浏览 1 评论 0原文

有没有办法配置 mysql 或 php,以便在查询中自动转义数据值?我读过有关 PDO 的内容,例如,Zend Framework 有一些自动执行此操作的数据库适配器 - 但在服务器端,是否没有任何配置可以避免必须在代码?

谢谢,

大卫

Is there a way to configure mysql or php so that in queries, data values are escaped automatically? I've read about PDO and that Zend Framework, for example, has some Database-Adapters that do it automatically - but on the server side, isn't there any configuration that can be done to avoid having to take care of it in the code?

Thanks,

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2024-12-17 20:18:40

是否可以进行任何配置来避免在代码中处理它?<​​/p>

不完全是,不。这已经被尝试过 - 结果是现在每个人都讨厌的可怕混乱。

没有“神奇功能”可以使查询安全 - 传递给查询的每个参数都需要进行不同的清理(例如字符串与整数)。有些东西(比如动态表和列名)根本无法清理(甚至不能使用数据库库的字符串转义方法),因此您需要将它们与现有表和列的列表进行比较。

使用 PDO 的预准备语句(或 Zend Framework 数据库函数,据我所知,其中包含 PDO)是您可以尽可能少做的最接近的方法。

isn't there any configuration that can be done to avoid having to take care of it in the code?

Not really, no. This has been tried - the result was a terrible mess that everyone hates now.

There is no "magic function" to make a query safe - every argument you pass to the query needs to be sanitized differently (like strings vs. integers). Some things (like dynamic table and column names) can't be sanitized at all (not even using the database library's string escaping method), so you need to compare them against a list of the existing tables and columns.

Using PDO's prepared statements (or the Zend Framework database functions, which AFAIK wrap PDO among others) is the closest you can get to doing as little as possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文