abstract:数据库新增、更新、删除<?php $pdo = new PDO('mysql:host=127.0.0.1;dbname=php_edu;charset=utf8','root','root'); //添加 //$sql = "INSERT IGNORE INT
数据库新增、更新、删除
<?php $pdo = new PDO('mysql:host=127.0.0.1;dbname=php_edu;charset=utf8','root','root'); //添加 //$sql = "INSERT IGNORE INTO `user` (`name`,`sex`,`age`,`email`,`password`,`status`,`create_time`) VALUES (:name,:sex,:age,:email,:password,:status,:create_time)"; //更新 //$sql = "UPDATE `user` SET `name` = :name,`email`= :email,`create_time` = :create_time WHERE `user_id` = :id"; //删除 $sql = "DELETE FROM `user` WHERE `user_id` = :id"; $stmt = $pdo ->prepare($sql); //$name = '张靓颖'; //$sex = 1; //$age = 33; //$email = 'zly@php.io'; //$password = sha1('123456'); //$status = 1; //$createTime = time(); //$id = 1; //$name = '过儿'; //$email = 'guoer@php.io'; //$createTime = time(); $id = 45; $stmt->bindParam(':id',$id,PDO::PARAM_INT); //$stmt->bindParam(':name',$name,PDO::PARAM_STR,20); //$stmt->bindParam(':email',$email,PDO::PARAM_STR,100); //$stmt->bindParam(':create_time',$createTime,PDO::PARAM_INT); if ($stmt -> execute()) { echo ($stmt -> rowCount() > 0) ? '成功删除了' .$stmt -> rowCount() .'条记录' : '没有记录被删除'; } else { exit(print_r($stmt ->errorInfo(),true)); }
截图:新增信息
截图:更新信息
截图:删除信息
Correcting teacher:查无此人Correction time:2019-07-20 13:04:04
Teacher's summary:完成的不错。pdo操作速度比之前的mysqli快很多。继续加油