Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
$sql = "INSERT INTO T_product (proid,proname,price,description) VALUES (?,?,?,?)";
// 预处理要执行的语句
$stmt = $dbh->prepare($sql);
$proid = '120019';
$proname = '笔记本';
$price = 12800;
$description = '华硕笔记本,高配置';
$flag = $stmt->execute([$proid,$proname,$price,$description]);
if($flag){
echo '添加成功'.$dbh->lastInsertId();
}else{
echo '添加失败';
die();
}
<?php
//预处理sql语句
$sql = 'DELETE from T_product WHERE id=?';
//准备要执行的语句
$stmt = $dbh->prepare($sql);
$delid = 2;
$flag= $stmt->execute([$delid]);
if($flag){
echo '删除成功';
}else{
echo '删除失败';
die(;)
}
$sql = 'SELECT * FROM T_product WHERE id>?';
$stmt = $dbh->prepare($sql);
$selectid = 1;
$stmt->execute([$selectid]);
$res = $stmt->fetchAll();
if ($res){
print_r($res);
}else{
die('查询失败');
}
$sql = 'UPDATE T_product SET proid=?,proname=?,price=? WHERE id=?';
$stmt = $dbh->prepare($sql);
$proid = '120016';
$proname = '手机';
$price = 2600;
$updateid=1;
$flag = $stmt->execute([$proid,$proname,$price,$updateid]);
if($flag){
echo '更新成功';
}else{
die('更新失败');
}