get number of rows with pdo

后端 未结 5 1386
自闭症患者
自闭症患者 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:20

    You've executed a query that returns rows from the database, fetched the first row from the result into a variable and then echo'd the first column of that row.

    If you want to count, do an SQL count()

    $result = $db->prepare("select count(*) from coursescompleted where person=:p"); 
    $result->bindParam(':p', $q, PDO::PARAM_INT);
    $result->execute();
    $rowCount = $result->fetchColumn(0);
    echo $rowCount;
    

提交回复
热议问题