《Mysql學習PHP mysqli擴展庫 預處理技術的使用分析》要點:
本文介紹了Mysql學習PHP mysqli擴展庫 預處理技術的使用分析,希望對您有用。如果有疑問,可以聯系我們。
MYSQL必讀1、使用mysqli擴展庫 預處置技術 mysqli stmt 向數據庫添加3個用戶
MYSQL必讀??? //mysqli擴展庫 預處置技術 mysqli stmt 向數據庫添加3個用戶
??? //1、創建mysqli對象
??? $mysqli = new MySQLi("localhost","root","root","test");
??? if($mysqli->connect_error){
??????? die($mysqli->conncet_error);
??? }
??? //2、創建預編譯對象
??? $sql="insert into user1(name,password,email,age) values(?,?,?,?)";
??? $mysqli_stmt=$mysqli->prepare($sql);
MYSQL必讀??? //綁定參數
??? $name="小芳";
??? $password="123456";
??? $email="xiaofang@126.com";
??? $age=18;
??? //參數綁定->給?號賦值 這里類型和次序要一致
??? $mysqli_stmt->bind_param("sssi",$name,$password,$email,$age);
MYSQL必讀??? //執行
??? $b=$mysqli_stmt->execute();
MYSQL必讀??? //繼續添加
MYSQL必讀??? $name="小楊";
??? $password="123456";
??? $email="xiaoyang@126.com";
??? $age=18;
??? //參數綁定->給?號賦值 這里類型和次序要一致
??? $mysqli_stmt->bind_param("sssi",$name,$password,$email,$age);
MYSQL必讀??? //執行
??? $b=$mysqli_stmt->execute();???
MYSQL必讀??? //繼續添加
MYSQL必讀??? $name="小G";
??? $password="123456";
??? $email="xiaoG@126.com";
??? $age=18;
??? //參數綁定->給?號賦值 這里類型和次序要一致
??? $mysqli_stmt->bind_param("sssi",$name,$password,$email,$age);
MYSQL必讀??? //執行
??? $b=$mysqli_stmt->execute();???
MYSQL必讀??? if(!$b){
??????? echo "操作失敗".$mysqli_stmt->error;
??? }else{
??????? echo "操作勝利";
??? }
??? //關閉預編譯
??? $mysqli_stmt->close();
??? $mysqli->close();
?>
MYSQL必讀??? //使用預處置查詢id>5的用戶id name email
??? $mysqli=new MySQLi("localhost","root","root","test");
??? if($mysqli->connect_error){
??????? die($mysqli->connect_error);
??? }
MYSQL必讀??? //創建預編譯對象
??? $sql="select id,name,email from user1 where id>?";
??? $mysqli_stmt=$mysqli->prepare($sql);
??? $id=5;
??? //綁定參數
??? $mysqli_stmt->bind_param("i",$id);
??? //綁定成果集
??? $mysqli_stmt->bind_result($id,$name,$email);
??? //執行
??? $mysqli_stmt->execute();
MYSQL必讀??? //取出綁定的值
??? while($mysqli_stmt->fetch()){
??????? echo "<br/>$id--$name--$email";
??? }
??? //關閉資源
??? //釋放成果
??? $mysqli_stmt->free_result();
??? //關閉與編譯語句
??? $mysqli_stmt->close();
??? //關閉連接
??? $mysqli->close();
MYSQL必讀必修>
《Mysql學習PHP mysqli擴展庫 預處理技術的使用分析》是否對您有啟發,歡迎查看更多與《Mysql學習PHP mysqli擴展庫 預處理技術的使用分析》相關教程,學精學透。維易PHP學院為您提供精彩教程。