Alternative for mysql_num_rows using PDO

后端 未结 5 1951
逝去的感伤
逝去的感伤 2020-11-27 18:41

Right now I have a PHP file that does a MYSQL query and then counts rows like this:

$count=mysql_num_rows($result);


if ($count == 1) {
    $message = array         


        
5条回答
  •  旧时难觅i
    2020-11-27 18:55

    Maybe you can use PDO's "fetchAll" method, which returns an array containing all the SELECT results. Then use "count" method to count the array's rows.

    Ex:

    $rows = $stmt->fetchAll();
    $num_rows = count($rows);
    

提交回复
热议问题