gpt4 book ai didi

php - 使用 count(*) 与 num_rows

转载 作者:IT王子 更新时间:2023-10-29 00:33:35 35 4
gpt4 key购买 nike

获取结果集中的行数有两种方式:

  1. 就是用query来获取count

    $query="Select count(*) as count from some_table where type='t1'";

    然后检索计数的值。

  2. 在 php 中通过 num_rows() 获取计数。

那么哪个性能更好?

最佳答案

如果您的目标是实际计算行数,请使用 COUNT(*)num_rows 通常(根据我的经验)仅用于确认返回的行数超过零并在这种情况下继续。与 COUNT 上的聚合相比,即使查询本身花费相同的时间,MySQL 也可能需要更长的时间来读取许多选定的行。

关于php - 使用 count(*) 与 num_rows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18409650/

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