我用PDO语句得到了这个函数,但我做错了:(我也知道。。。。
它是:foreach($result为$row);这就是我不能阅读的原因:if($row〔'active〕==='yes')
但在谷歌和stack上的搜索中,我找不到书面答案。有人能看看什么是正确的方法吗????我对PDO还是有点陌生:)
thnx处于高级状态。
include ('../../redir/mapping.php');
include ($dot2.$RMredir.$RFUserR);
$dbh = new PDO("mysql:host=".$Rhost.";dbname=".$RDB, $RDBsqlR, $RDBpassR);
$stmt = $dbh->prepare("SELECT * FROM `users` WHERE `email`=:email");
$stmt->bindParam(':email', $email,PDO::PARAM_STR);
$stmt->execute();
foreach ($result as $row);
if($stmt->rowCount() === 0)
{
$emailcheck = 'not_here';
}
else if($stmt->rowCount() === 1)
{
if($row['active'] === 'yes')
{
$emailcheck = 'here_and_active';
}
else if($row['active'] === 'no')
{
$emailcheck = 'here_and_not_active';
}
}
else
{
$emailcheck = 'error';
}
return $emailcheck;
您没有获取任何内容。在您的代码中$result为空:
使用fetch(PDO::FETCH_ASSOC);
来获取结果。尝试:
$dbh = new PDO("mysql:host=".$Rhost.";dbname=".$RDB, $RDBsqlR, $RDBpassR);
$stmt = $dbh->prepare("SELECT * FROM `users` WHERE `email`=:email");
$stmt->bindParam(':email', $email,PDO::PARAM_STR);
$stmt->execute();
$emailcheck = array();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() === 0){
$emailcheck[] = 'not_here';
}
else if($stmt->rowCount() === 1){
foreach ($result as $row){
if($row['active'] === 'yes'){
$emailcheck[] = 'here_and_active';
}
else if($row['active'] === 'no'){
$emailcheck[] = 'here_and_not_active';
}
}
}
else{
$emailcheck[] = 'error';
}
var_dump($emailcheck);