abstract:學(xué)完P(guān)DO數(shù)據(jù)庫篇后,知道了如何利用代碼來操作數(shù)據(jù)庫的,并牢記在操作刪除數(shù)據(jù)庫數(shù)據(jù)時(shí)一定要添加條件,不過代碼尚未熟練,任需多寫代碼,以下是數(shù)據(jù)庫刪除操作作業(yè)小案例。<?php $pdo = new PDO('mysql:host=127.0.0.1;dbname=1_c','root','root'); $sql&
學(xué)完P(guān)DO數(shù)據(jù)庫篇后,知道了如何利用代碼來操作數(shù)據(jù)庫的,并牢記在操作刪除數(shù)據(jù)庫數(shù)據(jù)時(shí)一定要添加條件,不過代碼尚未熟練,任需多寫代碼,以下是數(shù)據(jù)庫刪除操作作業(yè)小案例。
<?php $pdo = new PDO('mysql:host=127.0.0.1;dbname=1_c','root','root'); $sql = "DELETE FROM `user` WHERE `user_id`=`user_id`"; $stmt = $pdo->prepare($sql); $user_id = 3; $stmt->bindParam(':user_id',$user_id,PDO::PARAM_INT); if ($stmt->execute()){ echo ($stmt->rowCount()>0) ? '成功刪除'.$stmt->rowCount().'條用戶信息' : '用戶信息刪除失敗'; } else{ xit(print_r($stmt->errorInfo(),true)); }
Correcting teacher:韋小寶Correction time:2018-12-25 15:21:34
Teacher's summary:寫的還是挺不錯(cuò)的!pdo在實(shí)際的開發(fā)中隨處可見,課后還要記得多加練習(xí)??!