tp5의 트랜잭션 처리
1207 단어 트랜잭션 처리
function shiwu(){
//
$this->startTrans();
//
$data['video_status']=1;
$video_id=$this->insertGetId($data); //
if ($video_id){
//
$this->commit();
return $video_id;
}else{
//
$this->rollback();
}
}
예2:
//
public function chuli(){
db::startTrans();
$res = db('blog')->delete('14');
$res1 = db('blog')->delete('13');
if ($res && $res1){
//
db::commit();
echo "1";
}else{
//
db::rollback();
echo "2";
}
}
예3:
public function down(){
$user = session('usernames');
if(isset($user)){
db::startTrans();//
$res1 = db('')->del();
$res2 = db('')->del();
if($res1&&$res2){
db::commit();
return json(['status'=>'1','msg'=>' 5!']);
}else{
db::rollback();
return json(['status'=>'0','msg'=>' ']);
}
}else{
return json(['status'=>'0','msg'=>' !']);
}
}