Row count with PDO

前端 未结 23 3173
春和景丽
春和景丽 2020-11-21 22:57

There are many conflicting statements around. What is the best way to get the row count using PDO in PHP? Before using PDO, I just simply used mysql_num_rows.

23条回答
  •  天涯浪人
    2020-11-21 23:18

    function count_x($connect) {  
     $query = "  SELECT * FROM tbl WHERE id = '0' ";  
     $statement = $connect->prepare($query);  $statement->execute();  
     $total_rows = $statement->rowCount();  
     return $total_rows; 
    }
    

提交回复
热议问题