返回POD的增删盖......登陆

POD的增删盖茶

红色熊猫2019-06-15 14:45:16114

<?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();//返回寿影响的条数 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;

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送
  • PHP中文网