【发布时间】:2020-02-21 01:54:34
【问题描述】:
我有一些基本的 php 代码,它尝试根据数据库中的用户名和密码进行身份验证。如果用户和通行证成功匹配,则应该打印“已验证”。但是,查询没有返回任何数据。此外,我用来检查是否返回任何数据的 isset() 表明数组中有值。
这里出了什么问题,我怎样才能让这个 pdo 查询返回请求的数据?
这是有问题的代码。
$stmt = $pd->prepare("SELECT username from users where username = :logon and password = :passwd");
$stmt->bindParam(':logon', $_POST['username'], PDO::PARAM_STR);
$stmt->bindParam(':passwd', $_POST['password'], PDO::PARAM_STR);
$stmt->execute();
$verify_auth = $stmt->fetchAll();
if(isset($verify_auth)){
echo "Authenticated locally";
$authed = 1;
//do something here
}
elseif($authed != 1){
echo "<b>Failure to authenticate</b>";
}
即使凭据错误,每次运行“本地身份验证”时也是如此。
即使使用正确的凭据,verify_auth 数组似乎也始终为空。
post 参数分配成功。
【问题讨论】:
-
PDOStatement::fetchAll返回值:php.net/manual/en/…
标签: php postgresql pdo