I am wanting to some transactional mysql in my PHP, I have had a look at the PHP docs and there are a couple of functions I need to use,
mysqli_begin_transaction
mysqli_rollback
mysqli_commit
My code currently looks like this,
mysqli_begin_transaction($db_link, MYSQLI_TRANS_START_READ_WRITE);
$sql = "SELECT * FROM table";
$result = mysqli_query($sql);
if(!$result){
$rollback = true;
}
$sql = "SELECT * FROM another";
$result = mysqli_query($sql);
if(!$result){
$rollback = true;
}
$sql = "DELETE FROM table_name WHERE condition;"
mysqli_query($sql);
if(mysqli_affected_rows($db_link) < 0){
$rollback = true;
}
if($rollback){
mysqli_rollback($db_link)
} else {
mysqli_commit($db_link)
}
This is very rough pseudo code, but my question is that the transaction function all return values according to the php documentation so should I be wrapping them in conditional statements and throwing an exception of something similar if they dont return true.