get number of rows with pdo

后端 未结 5 1392
自闭症患者
自闭症患者 2020-12-16 00:29

I have a simple pdo prepared query:

$result = $db->prepare(\"select id, course from coursescompleted where person=:p\"); 
$result ->bindParam(\':p\', $         


        
5条回答
  •  情书的邮戳
    2020-12-16 01:18

    You can use this

    prepare("select id, course from coursescompleted where person=:p"); 
    $result ->bindParam(':p', $q, PDO::PARAM_INT);
    $result->execute();
    $rows = $result->rowCount();
    echo $rows;
    ?>
    

    This sometimes does not work on SELECT queries. But based on personal experience, and since you didn't mention porting it to other database systems, it should work on MySQL.

    More info is in PHP manual here

提交回复
热议问题