PHP 查询执行无误,但 return 计数为 0

PHP query execute without error but return count 0

我正在 angularjs 中创建登录,在 login.phppage 中,我通过行数验证用户是否存在,这意味着在 php pdo 中使用 rowCount() 但是它总是 return 0 结果。这是我的 php 文件:

<?php
   /*
   * Collect all Details from Angular HTTP Request.
   */ 
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $email = $request->email;
    $pass = $request->password;



    $user ="root";
$pass ="m2n1shlko";

$dbh = new PDO('mysql:host=localhost;dbname=blog_db', $user, $pass);

$query = $dbh->prepare("SELECT * FROM `signup_tbl` WHERE `email`='$email' AND `password`='$pass'");
$query->execute();
$count = $query->rowcount();
if($count>0){

echo "You have sucessfully login with this Email: ".$count; //this will go back under "data" of angular call.

}else{


  echo "Error While Authentication with this Email: " .$count;
}


    /*
     * You can use $email and $pass for further work. Such as Database calls.
    */    
?>

来自控制器的数据到达这里我不知道我在哪里遗漏了代码。如有帮助,不胜感激。谢谢

您将 $pass 覆盖到数据库(第 13 行)和用户(第 8 行)。将数据库密码更改为 $db_pass.

...
$email = '...';
$pass = $request->password;
...
$db_pass = '...';
...
$dbh = new PDO('mysql:host=localhost;dbname=blog_db', $user, $db_pass); // $pass to $db_pass

$query->rowCount();不是 $query->rowcount();

 $count = $query->rowCount();
 if($count>0){
 echo "You have sucessfully login with this Email: ".$count; //this will go back under "data" of angular call.
 }else{
 echo "Error While Authentication with this Email: " .$count;
 }

阅读手册rowCount

我已经在我的本地系统中完成了,它运行良好,像下面的例子一样尝试,这是有效的fine.just按照这个例子并正确地执行你的代码:

<?php
$host = "localhost";
$username = "root";
$password = "";
$dbname = "xxx";
// Create connection
$conn = new PDO('mysql:host=localhost;dbname=xxx', $username, $password);

$query =$conn->prepare("select * from testing");
$query->execute();
$count = $query->rowCount();
echo "Counting:".$count;
?>

输出:-

Counting:3