Row count with PDO

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

    I tried $count = $stmt->rowCount(); with Oracle 11.2 and it did not work. I decided to used a for loop as show below.

       $count =  "";
        $stmt =  $conn->prepare($sql);
        $stmt->execute();
       echo "\n";
       while($row = $stmt->fetch(PDO::FETCH_OBJ)) {
            $count++;
            echo "\n";
        foreach ($row as $item) {
        echo "\n";
            } //foreach ends
            }// while ends
            echo "
    ".($item !== null ? htmlentities($item, ENT_QUOTES):" ")."
    \n"; //echo " no of rows : ". oci_num_rows($stmt); //equivalent in pdo::prepare statement echo "no.of rows :".$count;

提交回复
热议问题