如果我有数据库表,users(name,job)
(john,Poster)
并且我MySQLi
使用此代码进行查询,那将有效。
$job = "Poster";
$statement = $con->prepare("SELECT * FROM users WHERE `job` = ?");
$statement->bind_param("s",$job);
$statement->execute();
$statement->bind_result($name,$job);
while ($statement->fetch()){
echo $name;
}
如果我做了$job = "NOTHING";
并且没有结果怎么办,那么我怎么能显示错误,例如echo "No reuslts found";
!$job
如果没有找到上面的代码,它不会显示任何内容。~ 谢谢
编辑 这个也没有用:(
$job = "NOTHING"; // should not found and should gives error
if ($statement = $con->prepare("SELECT * FROM users WHERE `job` = ?")){
$statement->bind_param("s",$job);
$statement->execute();
$statement->bind_result($name,$job);
while ($statement->fetch()){
echo $name;
}
}else{
echo "No results found dude";
}