PDO - get the result of a COUNT(*)?

后端 未结 2 1036
感情败类
感情败类 2020-12-10 19:42

During the new user registration process, I\'m trying to find whether a user name or a user email are already in the db. To do that, I want to find the number of rows where

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-10 19:51

    You could use ->fetchColumn(0) to get the 1 and only column from the next (one and only) rowset.

    if ( $query->fetchColumn(0) > 0 ){
      return false;
    } else return true;
    

提交回复
热议问题