ECOS事务处理实例

来源:互联网 发布:美国黑人政治正确知乎 编辑:程序博客网 时间:2024/06/07 12:11

       $objMdlaccount = app::get('sysuser')->model('account');

        $objMdlUser = app::get('sysuser')->model('user');


        $accountUser = $this->__preAccountUser($data);


        $db = app::get('sysuser')->database();

        $db->beginTransaction();

        try

        {

            if( !$userId = $objMdlaccount->insert($accountUser) )

            {

                throw new \LogicException('会员数据保存错误');

            }


            $userData = $this->__preUser($userId, $data);

            if( !$objMdlUser->insert($userData) )

            {

                throw new \LogicException('会员数据保存错误');

            }

            $db->commit();

        }

        catch (Exception $e)

        {

            $db->rollback();

            throw $e;

        }


        return $userId;


0 0