Answer the question
In order to leave comments, you need to log in
How to get the result of one of the queries in a transaction?
I am writing this. Does not work. Tell me what I'm doing wrong. How to get the result of a select?
mysqli_begin_transaction($resource,MYSQLI_TRANS_START_READ_WRITE);
$result = mysqli_query($resource,'SELECT id, address, picture FROM addresses LIMIT 1;');
$address = mysqli_fetch_assoc($result);
$is_deleted = mysqli_query($resource, "DELETE FROM addresses WHERE id = {$address['id']};");
$is_updated = mysqli_query($resource,"INSERT INTO payments VALUES ($userId, $productPrice)");
if ($is_updated && $is_deleted){
mysqli_commit($resource);
return $address;
}else{
mysqli_rollback($resource);
error_log('Transaction aborted');
return false;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question