I want to use Transactions in MySQL, my questions is that How I can check if the queries are submitted successfully or not? my query is:
mysql_query("START TRANSACTION");
$query_1 = mysql_query("DELETE FROM BLAH WHERE BLAH");
$query_2 = mysql_query("DELETE FROM BLAH WHERE BLAH");
mysql_query("COMMIT");
as far as I know, the above code does the transaction, but I want to check if the queries are submitted successfully or not, so:
mysql_query("START TRANSACTION");
$query_1 = mysql_query("DELETE FROM BLAH WHERE BLAH");
$query_2 = mysql_query("DELETE FROM BLAH WHERE BLAH");
if($query_1 && $query_2){
mysql_query(COMMIT);
}else{
mysql_query(ROLLBACK);
}
But I read somewhere that in transactions, the queries submit when we call "COMMIT
", so the above code should not work since while we check $query_1 && $query_2
, actually nothing is submitted to db since it's before the "COMMIT
" query, how I could perform such check?
Thanks in advance
P.S: Am I doing the whole thing right? please kindly let me know if there are also some other better ways... thanks