Row count with PDO

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

    To use variables within a query you have to use bindValue() or bindParam(). And do not concatenate the variables with " . $variable . "

    $statement = "SELECT count(account_id) FROM account
                      WHERE email = ? AND is_email_confirmed;";
    $preparedStatement = $this->postgreSqlHandler->prepare($statement);
    $preparedStatement->bindValue(1, $account->getEmail());
    $preparedStatement->execute();
    $numberRows= $preparedStatement->fetchColumn();
    

    GL

提交回复
热议问题