mysqli扩展库增强-预处理mysqli_stmt 批量查询显示结果

来源:互联网 发布:同花顺下载软件 编辑:程序博客网 时间:2024/05/26 08:43
<?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();  ?>

0 0