批改状态:合格
老师批语:
更新:
<?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);点击 "运行实例" 按钮查看在线实例


删除:
<?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);点击 "运行实例" 按钮查看在线实例


Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号