No active transactions'
P粉242741921
P粉242741921 2024-02-21 11:49:10
0
1
442

wipe_dataThere is a problem with this function

This wipe_data Function my database cleans and manages data insertion But this function shows error:

No active transactions

This is my code:

function wipe_data() {
     DB::beginTransaction();
     $adminData = User::where('role', 'admin')->first();  
    try {
        User::truncate();
        User_details::truncate();
        User_kyc::truncate();
        Token::truncate();`enter code here`
        $auto_id = date('Y');
        DB::statement("ALTER TABLE ls_users AUTO_INCREMENT = $auto_id");
        $admin = new User();
        $admin->username = $adminData->username;
        $admin->email = $adminData->email;
        $admin->password = $adminData->password;
        $admin->role = $adminData->role;
        $admin->save();
        $user_id = User::where('role', 'admin')->value('id');
        DB::commit();
    } catch (\Exception $ex) {
        DB::rollback();
        return false;
    }
    return true;
}

P粉242741921
P粉242741921

reply all(1)
P粉680087550

There are some statements that cause an implicit commit , including the ALTER TABLE statement you are using.

So, before calling DB::commit(), your statement has already been committed, so the error occurred.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template