PHPmysqli的 预处理执行查询语句
1 header( 'Content-Type:text/html;charset=utf-8 '); 2 require 'prepareSrarment.php'; 3 $mysqli=new mysqli("localhost", "root", "password, "user1", 3306); 4 $mysqli->set_charset("utf8"); 5 //使用预编译从数据库中查询 6 //使用预处理的方法,查询所有ID>5的用户 7 $sql="select id,name,email from user1 where id>?"; 8 $mysqli_stmt=$mysqli->prepare($sql) or die("1".$mysqli_stmt->error); 9 //绑定参数 10 $id=12; 11 $mysqli_stmt->bind_param("i", $id)or die($mysqli_stmt->error); 12 //绑定结果集 13 $mysqli_stmt->bind_result($id,$name,$email)or die($mysqli_stmt->error); 14 //执行 15 $mysqli_stmt->execute()or die("2".$mysqli_stmt->error); 16 17 while ($mysqli_stmt->fetch()){ 18 echo "<br/>---$id---$name----$email"; 19 } 20 $mysqli_stmt->free_result(); 21 $mysqli_stmt->close(); 22 $mysqli->close(); 23 ?>