PHP MySQL选择计数与准备好的陈述总是返回1

时间:2019-02-12 18:28:02

标签: php mysql sql

我正在使用此方法进行登录Web Service

function redeem() {
    if (isset($_POST["user"]) && isset($_POST["pass"]) && isset($_POST["computer"])) {
        $user = $_POST['user'];
        $pass = $_POST['pass'];
        $computer = $_POST['computer'];

        $galNumb = "SELECT COUNT(*) FROM Useres WHERE username = ? AND password = ?";
        $stmt = $this->db->prepare($galNumb);
        $stmt->bind_param('ss', $user, $pass);
        $gNumb = $stmt->execute();

        $result = array(
            "success" => "true",
        );
        $this->sendResponse(200, $gNumb);
        return true;
    }
    $this->sendResponse(400, 'Invalid request');
    return false;
}

问题在于,即使sql表不包含$gNumbusernamepassword始终返回1。知道可能是什么问题吗?

1 个答案:

答案 0 :(得分:1)

您忘了获取结果:

...
 $stmt->bind_param('ss', $user, $pass);
 if ($stmt->execute()) {
      $stmt->bind_result($gNumb);
      $stmt->fetch();
 } else {
      $gNumb = 0;
 }
...