<?php
//mysqli扩展库增强-预处理mysqli_stmt 批量查询显示结果
//1、创建mysql对象
$mysqli=new mysqli("127.0.0.1","root","password","testdb");
//验证是否连接成功
if($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
//2创建预编译对象
$sql="select id,name,email,age from user where id>?";
$mysqli_stmt=$mysqli->prepare($sql);
$id=5;
//绑定参数
$mysqli_stmt->bind_param("i",$id);
//执行
$mysqli_stmt->exeucte();
//取出绑定的值
while ($mysqli_stmt->fetcch()) {
//显示结果
echo"--$id--$name--$email--$age--"
}
//释放结果
$mysqli_stmt->free_result();
//关闭预编译语句
$mysqli_stmt->close();
//关闭连接
$mysqli->close();
?>
mysqli扩展库增强-预处理mysqli_stmt 批量查询显示结果
最新推荐文章于 2021-02-12 19:34:40 发布