PDO获取记录行数
                                                                
                20-08-18 17:58
                字数 346
                阅读 2156
                                            
            SQL如下
select * from `users` where create_time >= '2020-06-01 00:00:00'使用 rowCount() 方法是错误的,rowCount() 返回的是受影响行数。正确的做法是使用相同的条件放到 select count(*) 语句中。
select count(*) from `users` where create_time >= '2020-06-01 00:00:00'然后通过 fetchColumn 查询
$totalCount = $pdo->query("select count(*)  from `users` where {$sqlWhere}")->fetchColumn();1人点赞>
                    请登录后发表评论
        
        相关推荐
        
    文章归档
    
最新文章
        最受欢迎
    22-11-16 10:13
                    21-10-18 12:11
                    21-10-17 23:27
                    20-08-18 17:58
                    20-01-06 12:12
                     
         
                     
     
    
rowCount返回受影响行数,fetchColumn从结果集中的下一行返回单独的一列。
如果你的SQL是这样的 select count(*) from goods group by user_id,那么你需要用使用 rowCount方法,才能获取正确的记录条数。