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

后端 未结 2 1031
感情败类
感情败类 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;
    
    0 讨论(0)
  • 2020-12-10 20:12

    (Note: I haven't tested this, nor do I have PHP installed on my work machine to test it; I work in a C#/Java shop)

    Likely, you'd want $query->fetchColumn();

    You can also pass which column number you want, but it defaults to column 0.

    0 讨论(0)
提交回复
热议问题