我试图为查询使用预准备语句。 代码如下
<?php
$studentrollno=1;
$studentclass=10;
$studentsection='A';
$host="localhost";
$dbName="school_election_db"
$conn=new mysqli_connect($host,dbName);
if(conn->connect_error())
{
echo "error occured";
}
else
{
$stmt="SELECT * FROM voting_details where studentrollno=? and
studentclass=? and studentsection=?";
$conn->bind_param($studentrollno,$studentclass,$studentsection);
$result=$conn->execute();
if(result==true)
{
echo "login succesfull";
}
else
{
echo "Please try again";
}
?>
错误是围绕mysqli查询但我无法弄清楚错误。当我使用普通语句与程序PHP时,它正常工作。但我读到正常的方法是使用OOP和准备好的陈述 我得到的错误是&#34; mysqli_bind_param()::语句中的元素数量与绑定参数的数量不匹配&#34;。
答案 0 :(得分:3)
你应该使用准备
$dbName="school_election_db"
$conn=new mysqli_connect($host,dbName);
if(conn->connect_error())
{
echo "error occured";
}
else
{
$stmt= $conn->prepare("SELECT *
FROM voting_details
where studentrollno = ?
and studentclass = ?
and studentsection = ? ") ;
$stmt->bind_param('iis',$studentrollno,$studentclass, $studentsection);
$result=$stmt->execute();
if($result==true)
{
echo "login succesfull";
}
else
{
echo "Please try again";
}
?>