韩顺平php预编译技术(dml语句)

在这里插入图片描述

在这里插入图片描述
mysqli扩展库的预处理技术 mysqli stmt
预编译执行dml语句

<?php
//预编译演示
//创建mysqli对象
$mysqli=new MYSQLi("localhost","root","hsp123","test");
//2.创建预编译对象
$sql="insert into user1 (name,password,email,age)values(?,?,?,?)";
$mysqli_stmt=$mysqli->prepare($sql) or die($mysqli->error);

//绑定参数
$name="小倩";
$password="xiaoqian";
$email="[email protected]";
$age="200";
//参数绑定给问号赋值这里类型和顺序都要对应
$mysql_stmt->blind_praram("sssi",$name,$password,$email,$age)
//执行
$b=$mysqli_stmt->execute();

//继续添加
$name="老妖";
$password="laoyao";
$email="[email protected]";
$age="210";
$mysql_stmt->blind_praram("sssi",$name,$password,$email,$age)
//执行
$b=$mysqli_stmt->execute();

//继续添加
$name="采臣";
$password="aaa";
$email="[email protected]";
$age="30";
$mysql_stmt->blind_praram("sssi",$name,$password,$email,$age)
//执行
$b=$mysqli_stmt->execute();
if(!$b){
 error_log(老妖);

}

if(!$b){
 die("操作失败".$mysqli_stmt->error);
}else{
 echo "操作成功";
}
//
$mysql->close();
?>

猜你喜欢

转载自blog.csdn.net/weixin_43345480/article/details/89764275