Blogger Information
Blog 26
fans 0
comment 0
visits 19583
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0424预处理,更新删除
十一
Original
723 people have browsed it

更新:

实例

<?php
//1.连接数据库存
require 'conndb.php';
//2.准备SQL语名
$sql = "UPDATE staff SET salary=? WHERE staff_id=? ";
//3.创建STMT对象
$stmt = mysqli_stmt_init($db);
//4.检测SQL语句
if (mysqli_stmt_prepare($stmt,$sql)){
    /*参数绑定*/
    mysqli_stmt_bind_param($stmt, "ii", $salary,$staff_id);
    $salary = 6666;
    $staff_id = 9;

    mysqli_stmt_execute($stmt);
echo '更新了'.mysqli_stmt_affected_rows($stmt).'条记录;
} else {
    exit(mysqli_stmt_errno($stmt).':'.mysqli_stmt_error($stmt));
}
/* 注销stmt对象 */
mysqli_stmt_close($stmt);

/* 关闭数据库连接 */
mysqli_close($db);

运行实例 »

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

1.png

2.png

删除:

实例

<?php
//1.连接数据库存
require 'conndb.php';
//2.准备SQL语名
$sql = "DELETE FROM staff  WHERE staff_id=?";
//3.创建STMT对象
$stmt = mysqli_stmt_init($db);
//4.检测SQL语句
if (mysqli_stmt_prepare($stmt,$sql)){
    /*参数绑定,
//参数有以下四种类型:
//i - integer(整型)
//d - double(双精度浮点型)
//s - string(字符串)
//b - BLOB(binary large object:二进制大对象) */

mysqli_stmt_bind_param($stmt, "i",$staff_id);
    $staff_id = 9;

    mysqli_stmt_execute($stmt);
echo '删除了'.mysqli_stmt_affected_rows($stmt).'条记录.';
} else {
    exit(mysqli_stmt_errno($stmt).':'.mysqli_stmt_error($stmt));
}
/* 注销stmt对象 */
mysqli_stmt_close($stmt);

/* 关闭数据库连接 */
mysqli_close($db);

运行实例 »

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

1.png

2.png

Correction status:qualified

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