gpt4 book ai didi

php - 为什么当返回的行为 0 时 Wordpress $wpdb->query() 响应为 1

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:58:37 25 4
gpt4 key购买 nike

我在自定义函数中执行以下操作:

    $exists = $wpdb->query($wpdb->prepare('
SELECT COUNT(*)
FROM wp_%d_gdsr_data_article
WHERE post_id = %d

', $blog_id, $post_id));

即使查询没有返回任何行,$exists 的计算结果也是 1。此外,var_dump($wpdb->queries) 产生 NULL。有人知道这里发生了什么吗?

谢谢,

最佳答案

来自documentation :

The function returns an integer corresponding to the number of rows affected/selected. If there is a MySQL error, the function will return FALSE. (Note: since both 0 and FALSE can be returned, make sure you use the correct comparison operator: equality == vs. identicality ===).

查询返回 1 行,因此 query() 函数返回 1 - 并且对于您在其中发布的查询将始终返回 1您的问题,即使 COUNT 选择的行数为 0。使用 get_varget_rowget_results 按照 TheDeadMedic 的建议获取查询的实际结果,可能是 012

关于php - 为什么当返回的行为 0 时 Wordpress $wpdb->query() 响应为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2989845/

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