Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn how to use transactions for the first time. By the way, I will write them here.
/*
* Add hotel and room types
**/
Public function insertAll ($ arr_hotel = array (), $ arr_room = array ()){
$ Model = new Model ();
$ Model-> startTrans ();
$ Flag = false;
$ Hid = $ model-> table (C ('db _ prefix'). 'Hotel ')-> add ($ arr_hotel );
If ($ hid & count ($ arr_room) = 0) {// if no room type information is input, submit the data directly.
$ Model-> commit ();
$ Flag = true;
} Else if ($ hid & count ($ arr_room)> = 0) {// if the specified room type information exists, add the corresponding hotel ID and submit the ticket.
For ($ I = 0; $ I $ Arr_room [$ I] ['hid '] = $ hid;
}
$ Rid = $ model-> table (C ('db _ prefix'). 'room ')-> addAll ($ arr_room );
If ($ rid ){
$ Model-> commit ();
$ Flag = true;
}
}
If (! $ Flag ){
$ Model-> rollback ();
}
Return $ flag;
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB