Row count with PDO

前端 未结 23 3161
春和景丽
春和景丽 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:15

    Use parameter array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL), else show -1:

    Usen parametro array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL), sin ello sale -1

    example:

    $res1 = $mdb2->prepare("SELECT clave FROM $tb WHERE id_usuario='$username' AND activo=1 and id_tipo_usuario='4'", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
    $res1->execute();
    
    $count=$res1->rowCount();
    echo $count;
    

提交回复
热议问题