abstract:<?php//1连接数据库创建pdo对象$pdo = new PDO('mysql:host=127.0.0.1;dbname=php_edu','root','root');//2创建预处理对象$stmt//选择sql语句$sql = "UPDATE `user` SET`email`=:email,`creattime
<?php
//1连接数据库创建pdo对象
$pdo = new PDO('mysql:host=127.0.0.1;dbname=php_edu','root','root');
//2创建预处理对象$stmt
//选择sql语句
$sql = "UPDATE `user` SET`email`=:email,`creattime`=:creattime WHERE `user_id`=:user_id";
//3验证sql语句,生成预处理对象
$stmt=$pdo->prepare($sql);
//4参数绑定
$id=2;
$email='dongfnag@qq.com';
$creattime=time();
$stmt->bindParam('user_id',$id,PDO::PARAM_INT,20);
$stmt->bindParam('email',$email,PDO::PARAM_STR,20);
$stmt->bindParam('creattime',$creattime,PDO::PARAM_INT,20);
//5执行添加}
if ($stmt->execute()){
echo ($stmt->rowCount()>0 ? '成功添加了'.$stmt->rowCount().'条记录':'没有记录被添加');
}else {
exit(print_r($stmt->errorInfo(), true));
Correcting teacher:查无此人Correction time:2019-03-07 09:06:53
Teacher's summary:完成的不错。现在pdo已经替代了mysqli,所以只要好好学习pdo就行了,继续加油