我刚刚将我的 SQLi 转换为 PDO。我不是 100% 确定如何准备 PDO 语句以包含ERROR
orSUCCESS
语句。我在下面包含了我的部分代码:
// query
$sql = "INSERT INTO data (avatar,citid,birthday,citname,level,experience,rank,rankimage,elite_citizen,points,strength,status,citizenship,mu,date) VALUES (:avatar,:citid,:birthday,:citname,:level,:experience,:rank,:rankimage,:elite_citizen,:points,:strength,:status,:citizenship,:mu,:date)";
$q = $conn->prepare($sql);
$q->execute(array(':avatar'=>$avatar,':citid'=>$citid,':birthday'=>$birthday,':citname'=>$citname,':level'=>$level,':experience'=>$experience,':rank'=>$rank,':rankimage'=>$rankimage,':elite_citizen'=>$elite_citizen,':points'=>$points,':strength'=>$strength,':status'=>$status,':citizenship'=>$citizenship,':mu'=>$mu,':date'=>$date));
在 MYSQL 中,我发现使用下面的语句更容易:
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
}
else {
echo "ERROR";
}
我将如何为 PDO 完成相同的任务?