You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$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.
Activity
dg commentedon Jan 21, 2025
It's better to consult the forum https://forum.nette.org/en/f71-database-orm