日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

PHP mysqli擴(kuò)展庫 預(yù)處理技術(shù)的使用分析_MySQL教程

編輯Tag賺U幣

推薦:mysql使用source 命令亂碼問題解決方法
從windows上導(dǎo)出一個sql執(zhí)行文件,再倒入到unbutn中,結(jié)果出現(xiàn)亂碼,折騰7-8分鐘,解決方式在導(dǎo)出mysql sql執(zhí)行文件的時候,指定一下編碼格式

1、使用mysqli擴(kuò)展庫 預(yù)處理技術(shù) mysqli stmt 向數(shù)據(jù)庫添加3個用戶

復(fù)制代碼 代碼如下:hl5o.cn

<?php

//mysqli擴(kuò)展庫 預(yù)處理技術(shù) mysqli stmt 向數(shù)據(jù)庫添加3個用戶
//1、創(chuàng)建mysqli對象
$mysqli = new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die($mysqli->conncet_error);
}
//2、創(chuàng)建預(yù)編譯對象
$sql="insert into user1(name,password,email,age) values(?,?,?,?)";
$mysqli_stmt=$mysqli->prepare($sql);

//綁定參數(shù)
$name="小芳";
$password="123456";
$email="[email protected]";
$age=18;

//參數(shù)綁定->給?號賦值 這里類型和順序要一致
$mysqli_stmt->bind_param("sssi",$name,$password,$email,$age);

//執(zhí)行
$b=$mysqli_stmt->execute();

//繼續(xù)添加

$name="小楊";
$password="123456";
$email="[email protected]";
$age=18;

//參數(shù)綁定->給?號賦值 這里類型和順序要一致
$mysqli_stmt->bind_param("sssi",$name,$password,$email,$age);

//執(zhí)行
$b=$mysqli_stmt->execute();

//繼續(xù)添加

$name="小G";
$password="123456";
$email="[email protected]";
$age=18;

//參數(shù)綁定->給?號賦值 這里類型和順序要一致
$mysqli_stmt->bind_param("sssi",$name,$password,$email,$age);

//執(zhí)行
$b=$mysqli_stmt->execute();

if(!$b){
echo "操作失敗".$mysqli_stmt->error;
}else{
echo "操作成功";
}
//關(guān)閉預(yù)編譯
$mysqli_stmt->close();
$mysqli->close();
?>


2、使用預(yù)處理查詢id>5的用戶id name email
復(fù)制代碼 代碼如下:hl5o.cn

<?php

//使用預(yù)處理查詢id>5的用戶id name email
$mysqli=new MySQLi("localhost","root","root","test");
if($mysqli->connect_error){
die($mysqli->connect_error);
}

//創(chuàng)建預(yù)編譯對象
$sql="select id,name,email from user1 where id>?";
$mysqli_stmt=$mysqli->prepare($sql);

$id=5;
//綁定參數(shù)
$mysqli_stmt->bind_param("i",$id);
//綁定結(jié)果集
$mysqli_stmt->bind_result($id,$name,$email);
//執(zhí)行
$mysqli_stmt->execute();

//取出綁定的值
while($mysqli_stmt->fetch()){
echo "<br/>$id--$name--$email";
}

//關(guān)閉資源
//釋放結(jié)果
$mysqli_stmt->free_result();
//關(guān)閉與編譯語句
$mysqli_stmt->close();
//關(guān)閉連接
$mysqli->close();

?>


分享:擁有5星評級數(shù)據(jù)庫表結(jié)構(gòu) 如何才能更高效的使用?
本篇文章介紹了,擁有5星評級數(shù)據(jù)庫表結(jié)構(gòu) 如何才能更高效的使用的方法。需要的朋友參考下

來源:模板無憂//所屬分類:MySQL教程/更新時間:2013-05-03
相關(guān)MySQL教程