Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
$sql = 'INSERT `staff` SET `name`=?, `sex` = ?, `email`=?;';
$data = ['张三', 1, 'zhangsan@qqq.om'];
$sql = 'INSERT `staff` SET `name`=:name, `sex` = :sex, `email`=:email;';
$data = ['name' => '小龙女','sex' => 0, 'email' => 'xiaolongnu@qqq.om'];
$sql = <<< SQL
INSERT `staff`
SET `name` = ?, `sex` = ?, `email` = ?;
SQL;
list($name, $sex, $email) = ['欧阳克', 0 , 'hongqigong@qq.com'];
$stmt->bindValue(1, $name, PDO::PARAM_STR);
$stmt->bindValue(2, $sex, PDO::PARAM_INT);
$stmt->bindValue(3, $email, PDO::PARAM_STR);
$stmt->bindParam(1, $name, PDO::PARAM_STR);
$stmt->bindParam(2, $sex, PDO::PARAM_INT);
$stmt->bindParam(3, $email, PDO::PARAM_STR);
list($name, $sex, $email) = ['郭靖456', 0 , 'hongqigong@qq.com'];
if (false === stripos($sql, 'where')) {
exit('禁止无条件更新');
}
$stmt = $db->prepare($sql);
$data = ['八戒', 0 , 'bajie@qq.com', 6];
if (false === stripos($sql, 'where')){
exit('禁止无条件删除 ');
}
if($stmt->execute([3])){
if ($stmt->rowCount() > 0){
//成功 success
echo '成功的删除了,' . $stmt->rowCount() . '条记录~~~';
}else{
//主要用于检测是否重复执行
echo '没有记录被删除';
print_r($stmt->errorInfo());
}
}else{
//false
echo 'Sql执行失败';
print_r($stmt->errorInfo());
}
$stmt->bindValue(1, 5, PDO::PARAM_INT);
if($stmt->execute()){
while ($staff = $stmt->fetch(PDO::FETCH_ASSOC)){
printf('<pre>%s</pre>', print_r($staff,true));
}
}else{
//false
echo 'Sql执行失败';
print_r($stmt->errorInfo());
}