Skip to content

Transaction is not working #316

@mitmelon

Description

@mitmelon

Transactions not working.

See sample

$db->transaction(function ($db) use ($data) {
  
            $db->query('INSERT INTO users ?', $data);
            $onboardId = $db->getInsertId();
            if(isset($onboardId) and !empty($onboardId)){
                //Now lets create user balance
                $balanceData = array(
                    'username' => $data['username'],
                    'acnumber' => $data['acnumber'],
                    
                    'loan' => 0,
                    'email' => $data['email'],
                    'balance' => 10000000
                );
                $db->query('INSERT INTO trans ?', $balanceData);
               
                exit(json_encode(['code' => 200, 'success' => true, 'message' => 'success']));
            } else {
                //Log error and send to developer - This will be implemented later
                exit(json_encode(['code' => 400, 'success' => false, 'message' => 'Something went wrong. Please try again later']));
            }
        });

If the trans table fails the users table does not roll back... Have tried using $db->beginTransaction() too none of the transaction methods are working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions