Home >php教程 >php手册 >多表事务处理

多表事务处理

WBOY
WBOYOriginal
2016-06-07 11:44:481208browse

第一次用到事务,顺便就写在这里了
    /*<br>      * 添加酒店和房型<br>      * */<br>     public function insertAll($arr_hotel=array(),$arr_room=array()){<br> <br>         $model = new Model();<br>         $model->startTrans();<br>         $flag=false;<br> <br>         $hid = $model->table(C('DB_PREFIX').'hotel')->add($arr_hotel);<br>         if( $hid && count($arr_room) ==0 ){//如果没有传入房型的信息则,直接提交数据<br>             $model->commit();<br>             $flag=true;<br>         }else if( $hid && count($arr_room) >= 0){//存在对应房型信息,则添加对应的酒店编号,并处理提交<br>             for($i=0 ; $i<count></count>                 $arr_room[$i]['hid'] = $hid;<br>             }<br>             $rid = $model->table(C('DB_PREFIX').'room')->addAll($arr_room);<br>             if( $rid ){<br>                 $model->commit();<br>                 $flag=true;<br>             }<br>         }<br> <br>         if(!$flag){ <br>                $model->rollback();<br>         }<br>         return $flag;<br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn