I have a typical transaction of
START TRANSACTION
INSERT INTO ...
UPDATE ...
DELETE ...
COMMIT
Problem 1: Failure in UPDATE will not block the transaction. In single query, I use mysql_affected_rows() to inspect the success of UPDATE but how to do so in the middle of a Transaction?
Problem 2: How to detect which query caused the transaction stop? To make a if condiction in PHP?
Assuming you are using the
mysql_*()functions based on your mention ofmysql_affected_rows(), you should simply be calling each stage of the transaction in its ownmysql_query()and checking its success or failure at each stage. Unless you wrap this as a stored procedure, you have to call these as individual statements sincemysql_query()doesn’t support multiple statements in one call.