Alternative for mysql_num_rows using PDO

后端 未结 5 1947
逝去的感伤
逝去的感伤 2020-11-27 18:41

Right now I have a PHP file that does a MYSQL query and then counts rows like this:

$count=mysql_num_rows($result);


if ($count == 1) {
    $message = array         


        
5条回答
  •  萌比男神i
    2020-11-27 19:15

    If you are not using prepared statements then try:

    $find = $dbh->query('SELECT count(*) from table');
    if ($find->fetchColumn() > 0){
        echo 'found';
    }
    

    However, if you choose prepared statements, which i highly recommend, then:

    $find = $dbh->prepare('SELECT count(*) from table');
    $find->execute();
    if ($find->fetchColumn() > 0){
        echo 'found';
    }
    

提交回复
热议问题