本文實(shí)例講述了php+mysqli使用預(yù)處理技術(shù)進(jìn)行數(shù)據(jù)庫查詢的方法。分享給大家供大家參考。具體如下:
代碼有些難度,需要基礎(chǔ)知識(shí)比較扎實(shí)才能好理解,代碼先放上來:
這里實(shí)現(xiàn)查詢所有 id>5 的 id,title,contents值:
復(fù)制代碼 代碼如下:
$mysqli = new MySQLi("localhost","root","123456","liuyan");
if(!$mysqli){
?die($mysqli->error);
}
//創(chuàng)建一個(gè)預(yù)定義的對(duì)象 ?占位
$sql = "select id,title,contents from news where id>?";
$mysqli_stmt = $mysqli->prepare($sql);
$id=10;
//綁定參數(shù)
$mysqli_stmt->bind_param("i",$id);
//綁定結(jié)果集
$mysqli_stmt->bind_result($id,$title,$contents);
//執(zhí)行
$mysqli_stmt->execute();
//取出綁定的結(jié)果集
while($mysqli_stmt->fetch()){
?echo "--$id--$title--$contents--
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
PHP怎么學(xué)習(xí)?PHP怎么入門?PHP在哪學(xué)?PHP怎么學(xué)才快?不用擔(dān)心,這里為大家提供了PHP速學(xué)教程(入門到精通),有需要的小伙伴保存下載就能學(xué)習(xí)啦!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)