<?php $mysqli = new MySQLi("localhost","root","root","sziitjx"); if(!$mysqli){ die($mysqli->error); } //创建一个预定义的对象 ?占位 // $sql = "select state from servicer where servicer_id=? and password=?"; $sql = "call login(?,?)"; $mysqli_stmt = $mysqli->prepare($sql); $id='1501090103'; $pw='123456'; //绑定参数 $mysqli_stmt->bind_param("ss",$id,$pw); //绑定结果集 $mysqli_stmt->bind_result($state); //执行 $mysqli_stmt->execute(); //取出绑定的结果集 while($mysqli_stmt->fetch()){ echo "--$state--<hr>"; } //关闭结果集 $mysqli_stmt->free_result(); $mysqli_stmt->close(); $mysqli->close(); ?>
$sql = "select state from servicer where servicer_id=? and password=?";
执行上面这句返回的结果为1
$sql = "call login(?,?)";
执行这句却出错
Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement
select state from servicer where servicer_id=user_id and password=pw;
存储过程是上面这句,附带两个参数
IN `user_id` char(20),IN `pw` char(20)