Blogger Information
Blog 42
fans 3
comment 2
visits 40512
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Mysqli 面向对象的预处理技术实现更新操作
虞者自愚的博客
Original
586 people have browsed it

Mysqli 面向对象的预处理技术实现更新操作

实例

<?php
// 1.连接数据库
require 'mysqli_connect.php';
// 2.准备SQL语句
$sql = "UPDATE staff SET gongzi=? WHERE staff_id=?;";
//3.创建预处理对象STMT
$stmt = $mysqli ->stmt_init();
//4.检测STMT对象
if($stmt->prepare($sql)){
//1.绑定参数
$stmt->bind_param('si',$gongzi,$id);
// 5.执行SQL语句
$id=6;
$gongzi=8500;
$stmt->execute();

if($stmt->affected_rows>0){
    echo '<br>更新成功'.$stmt->affected_rows.'条记录';
}else{
    echo '<br />没有记录更新';
}
}else{
    exit($stmt->errno.':'.$stmt->error);
}


//关闭连接
$mysqli->close();
?>

运行实例 »

点击 "运行实例" 按钮查看在线实例



删除 更新 新增使用方法一样,修改SQL语句及绑定参数对象就行了

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