Row count with PDO

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

    For straight queries where I want a specific row, and want to know if it was found, I use something like:

    function fetchSpecificRow(&$myRecord) {
        $myRecord = array();
        $myQuery = "some sql...";
        $stmt = $this->prepare($myQuery);
        $stmt->execute(array($parm1, $parm2, ...));
        if ($myRecord = $stmt->fetch(PDO::FETCH_ASSOC)) return 0;
        return $myErrNum;
    }
    

提交回复
热议问题