gpt4 book ai didi

php - 查询中带引号的参数不起作用

转载 作者:行者123 更新时间:2023-11-29 22:46:29 24 4
gpt4 key购买 nike

所以我有这个代码:

 $infos['title'] = addslashes("Le Roi D'Australie");
$offer = get_page_by_title($infos['title'], ARRAY_A, 'post');

这不起作用,而我所有其他没有引用的帖子实际上都运行良好。

你有答案了吗? get_page_by_title 应该为我转义标题..我一定错过了什么。

提前谢谢您。

最佳答案

wpdb->prepare (由 get_page_by_title 使用)已经在使用参数化形式时正确防止 SQL 注入(inject)。

All data in SQL queries must be SQL-escaped before the SQL query is executed to prevent against SQL injection attacks. The prepare method performs this [SQL-escaping] functionality for WordPress.

只需删除 addslashes 调用,因为它会添加一个无用/额外的斜杠,从而导致查询失败。无论哪种情况,它都是有效的 SQL(感谢 prepare),但它使用了 now-over-slashed-value。

然后read through this question/answer了解为什么addslashes 对于 SQL 来说永远都不正确。 (最好的解决方案是仅使用 wpdb->prepare 或类似的占位符模型以及使用它的方法。)

关于php - 查询中带引号的参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29083809/

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