通过php预处理查询数据

<?php
//php使用预编译技术进行查询操作
$mysqli=new mysqli("localhost","root","123456","worddb");
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
//我们在users表当中查询id>3的用户
$sql="select * from users where id>?";
//创建预编译对象
$mysqli_sta=$mysqli->prepare($sql);
//绑定参数
$id=3;
$mysqli_sta->bind_param("i",$id);
//绑定结果集
$mysqli_sta->bind_result($id,$name,$age,$email);
$mysqli_sta->execute();
//取出绑定的值
while (($mysqli_sta->fetch())){
echo "<br/>$id--$name--$email";
}
//关闭资源
//释放结果
$mysqli_sta->free_result();
//关闭预编译命令
$mysqli_sta->close();
//关闭连接
$mysqli->close();
?>

你可能感兴趣的:(通过php预处理查询数据)