abstract:<?php/** * Created by PhpStorm. * User: Administrator * Date: 2019/6/15 * Time: 10:18 */try{ $pdo=new PDO('mysql:host=127.0.0.1;port=3306;dbname=hediwangluo;charset=utf8','
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/6/15
* Time: 10:18
*/
try{
$pdo=new PDO('mysql:host=127.0.0.1;port=3306;dbname=hediwangluo;charset=utf8','root','root');
}catch (PDOException $e){
die("Error".($e->getMessage()));
}
//增加
//$sql_add="insert into cmf_option values (:id,:autoload,:option_name,:option_value)";//必須寫全字段,
$sql_add="insert into cmf_option (`autoload`,`option_name`) values (:autoload,:option_name)";//無需寫全字段
$stm_add=$pdo->prepare($sql_add);
$arr_add=[
// ':id'=>122,
':autoload'=>'122',
':option_name'=>'2334',
// ':option_value'=>'44444',
];
if($stm_add->execute($arr_add)){
echo $stm_add->rowCount();
}else{
exit(print_r($stm_add->errorInfo()));
}
//刪除
$sql_del="delete from cmf_option where id<:id";
$stm_del=$pdo->prepare($sql_del);
if ($stm_del->execute([':id'=>100])){
echo $stm_del->rowCount();//返回壽影響的條數(shù) 5
}else{
exit(print_r($stm_del->errorInfo()));
}
//更新
$sql_up="UPDATE cmf_option SET autoload=:autoload ,option_value=:option_value where id=:id";
$stm_up=$pdo->prepare($sql_up);
if ($stm_up->execute([':id'=>124,':autoload'=>11,':option_value'=>'hahaahh'])){
echo $stm_up->rowCount();
}else{
exit(print_r($stm_up->errorInfo()));
}
//查詢
$sql="select * from cmf_option where id>=:id";
$stm = $pdo->prepare($sql);
if($stm->execute([':id'=>3])){
$res=$stm->fetchAll(PDO::FETCH_ASSOC);
}else{
exit(print_r($stm->errorInfo()));
}
$stm=null;
$pdo=null;
Correcting teacher:天蓬老師Correction time:2019-06-15 17:12:11
Teacher's summary:你的作業(yè)中, 對于一些基本的術(shù)語都沒有寫到, 例如 PDO, 不是POD, 錯(cuò)別字太多.....
還有, 在項(xiàng)目上線后, 對于語句執(zhí)行錯(cuò)誤的檢測代碼要注釋掉或刪除, 以免泄漏數(shù)據(jù)庫的信息