Blogger Information
Blog 34
fans 0
comment 0
visits 28438
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
424使用预处理技术简化实现更新与删除操作
1A7498的博客
Original
567 people have browsed it
<?php
require 'mysqli_connect2.php';
$sql = "UPDATE IGNORE staff SET name=?,sex=?,age=?,salary=? WHERE staff_id=?;";// 准备 sql 语句
$stmt = mysqli_stmt_init($db);//创建并初始化预处理对象stmt
mysqli_stmt_prepare($stmt, $sql);//用stmt对象处理当前预处理语句
mysqli_stmt_bind_param($stmt, 'siiii', $name, $sex, $age, $salary, $staff_id);// 变量与语句中的占位符进行绑定
$staff_id = 18;
$name = '八荒六唯我独尊功9';
$sex = 0;
$age = 99;
$salary = 99999;
mysqli_stmt_execute($stmt);//执行 sql 语句
echo '更新成功,主键id是:'.$staff_id;
mysqli_stmt_close($stmt);
mysqli_close($db);
?>

gengxin.png

gengxin2.png

<?php
require 'mysqli_connect2.php';
$sql = "DELETE FROM staff WHERE staff_id=?";// 准备 sql 语句
$stmt = mysqli_stmt_init($db);//创建并初始化预处理对象stmt
mysqli_stmt_prepare($stmt, $sql);//用stmt对象处理当前预处理语句
mysqli_stmt_bind_param($stmt, 'd', $staff_id);// 变量与语句中的占位符进行绑定
$staff_id = 21;
mysqli_stmt_execute($stmt);//执行 sql 语句
echo '删除成功,主键id是:'.$staff_id;
mysqli_stmt_close($stmt);//注销预处理对象
mysqli_close($db);//关闭数据连接
?>

delete.png

QQ截图20180428115407.pngQQ截图20180428115407.png

WHERE 语句后面的变量绑定直接在参数后面加一个即可mysqli_stmt_bind_param($stmt, 'siiii', $name, $sex, $age, $salary, $staff_id);



Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
  • 2018-03-16 11:39:01