View Code
 1 <?php
 2 
 3     //*******使用预处理的方式查询数据库*******//
 4 
 5     //创建mysqli对象
 6     $mysqli=new MySQLi("服务器地址","用户名","密码","数据库");
 7 
 8     //创建预编译对象
 9     $sql="select id,name,email from user where id>?";
10     $mysqli_stmt=$mysqli->prepare($sql) or die($mysqli->error);
11 
12     //准备数据
13     $id="";
14 
15     //绑定参数
16     $mysqli_stmt->bind_param("i",$id);
17     //绑定结果集
18     $mysqli_stmt->bind_result($id,$name,$email);
19     //执行
20     $mysqli_stmt->execute();
21 
22     //取出结果集
23     while($mysqli_stmt->fetch()){
24         echo "<br/>--$id--$name--$email";
25     }
26 
27     //释放结果集
28     $mysqli_stmt->free_result();
29     //释放预编译对象
30     $mysqli_stmt->close();
31     //关闭连接
32     $mysqli->close();
33 
34 ?>

 

posted on 2012-06-08 11:06  捣乃忒  阅读(147)  评论(0编辑  收藏  举报