Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction is not working #316

Open
mitmelon opened this issue Jan 21, 2025 · 1 comment
Open

Transaction is not working #316

mitmelon opened this issue Jan 21, 2025 · 1 comment

Comments

@mitmelon
Copy link

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.

@dg
Copy link
Member

dg commented Jan 21, 2025

It's better to consult the forum https://forum.nette.org/en/f71-database-orm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants