#重新父类的add方法 Public Function Add () {#同时操作多装表, you can consider using a transaction to either insert the data successfully or not plug in the input data. #开启事务的前提是表的引擎必须是InnoDB #开启事务//mysql_query ("STRAT TRANSACTION"); #--------------(1) basic information for inserting the item------------#判断是否插件成功 if (($goods _id=parent::add ()) ===false) {return FALSE; #--------------(2) Insert Member Price------------#判断是否有POST数据提交过来 if (isset ($_post[' Ml])) {#实例化会员价格模型 $Mb _price= M (' Memberprice '); #循环post提交过来的数据 foreach ($_post[' Ml ') as $k = + $v) {#插入数据 $is _ok= $Mb _price->data (Array ( ' goods_id ' = $goods _id, ' level_id ' and $k, ' price ' = ' $v, ')->add (); /*if ($is _ok===false) {mysql_query ("ROLLBACK"); return FALSE;} */}} #--------------(3) Insert commodity attribute-----------#判断POST提交过来是否有数据 if (isset ($_post[' goodsattr ')) {# Create a property Model $good _attr=m (' goodsattr '); #循环读取post提交过来的数据 foreach ($_post[' goodsattr ') as $k = + $v) {#在判断属性提交过来的是否是一个数组 such as: Color white black golden .... if (i S_array ($v) {#在循环这个属性的数组 foreach ($v as $k 1=> $v 1) {#在循环插件数据, $is _ok= $good _attr->data (Array ( ' goods_id ' = $goods _id, ' attr_id ' + $k, ' attr_value ' + $v 1,)]->add (); /* if ($is _ok===false) {mysql_query ("ROLLBACK"); return FALSE; } */}}else{#说明是单个值 $is _ok= $good _attr->data (' goods_id ' = $goods _id, ' attr_id ' = $k, ' attr_value ' + $v,)]->add (); /* if ($is _ok===false) {mysql_query ("ROLLBACK"); return FALSE; }*/ } } } }
Thinkphp handles multiple tables with transactions when the item is added.