PHPmysqli的 预处理执行查询语句
生活随笔
收集整理的這篇文章主要介紹了
PHPmysqli的 预处理执行查询语句
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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 //使用預(yù)編譯從數(shù)據(jù)庫中查詢
6 //使用預(yù)處理的方法,查詢所有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 //綁定參數(shù)
10 $id=12;
11 $mysqli_stmt->bind_param("i", $id)or die($mysqli_stmt->error);
12 //綁定結(jié)果集
13 $mysqli_stmt->bind_result($id,$name,$email)or die($mysqli_stmt->error);
14 //執(zhí)行
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 ?>
?
轉(zhuǎn)載于:https://www.cnblogs.com/tl542475736/p/3428557.html
總結(jié)
以上是生活随笔為你收集整理的PHPmysqli的 预处理执行查询语句的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdfs命令,hadoop基本常用命令
- 下一篇: LaTex安装及快速入门使用