查询不会产生任何结果。变量响应应该保存查询结果,但是当我测试它包含使用var_dump时,它表明它是空的。
try
{
$bdd = new PDO('mysql:host=localhost;dbname=ems', 'root', '');
} catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$code=123456;
$query = $bdd->prepare('SELECT Code,sender FROM info WHERE Code = ?');
//,reciever,origin,destination,transit
$query->execute(array($code));
if($query->fetchColumn())
{
echo"good";
while($reponse = $query->fetch()){
var_dump($reponse);
echo"good";
echo $reponse['sender'];
}
} else{
echo" The Code entered was not found please verify and enter again";
}
答案 0 :(得分:0)
我不确定这是否只是代码中的拼写错误,但我注意到了这段代码:
if($query->fetchColumn())
{
echo"good";
while($reponse = $query->fetch()){
var_dump($reponse);
echo"good";
echo $reponse['sender'];
}
else{
echo" The Code entered was not found please verify and enter again";
}
}
查看您的代码(以及您的评论),{
语句有一个开括号if
,后跟while
循环的开括号。然后有一个闭合支撑。右括号}
用于while
循环。然后你有一对else
块的大括号。在}
阻止之后,您还有另一个else
。尝试在}
阻止之前添加else
,并在}
阻止后移除else
之一。 else
块不应嵌套在if
块中(如果我完全理解你的话)。这是语法错误。
代码的外观如何:
if($query->fetchColumn())
{
echo"good";
while($reponse = $query->fetch()){
var_dump($reponse);
echo"good";
echo $reponse['sender'];
}
}
else{
echo" The Code entered was not found please verify and enter again";
}