pdo更新数据


$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

//
准备SQL语句,占位符我们不再用?,用"命名占位符" $sql="update erj_user set freeze_money=:freeze_money where id=:id ";

//创建预处理对象
$stmt
= $pdo->prepare($sql);
$stmt->execute(['freeze_money'=>$cha_freeze_money,'id'=>$row['user_id']]); 
$data_stmt
=$stmt->rowCount();

 

       $res_1=$redis->zadd('frozen_user',$time,json_encode(['task'=>'frozen_user','task_time'=>$time,'task_params'=>['frozen_id'=>$lastId,'user_id'=>$row['buy_id']]]));

       if($res_1){
           $buy_id=$row['buy_id'];
           $sql="update erj_user set usermoney=:usermoney,sellmoney=:sellmoney,freeze_money=:freeze_money where id=:id ";
           //创建预处理对象
           $stmt = $pdo->prepare($sql);
           $stmt->execute(['usermoney'=>0,'sellmoney'=>0,'freeze_money'=>$tot_freeze_money,'id'=>$buy_id]);


           $data_stmt=$stmt->rowCount();
           if($stmt->rowCount()>0)
           {
               echo '<h3>成功更新'.$stmt->rowCount().'条</h3>';
           }else
           {
               echo '<h3>更新失败</h3>';
               print_r($stmt->errorInfo());
               exit;
           }


       }

 

posted @ 2020-12-19 11:56  大熊童鞋  阅读(259)  评论(0编辑  收藏  举报