Reputation: 4565
I am using old-style mysql_query()
functions to perform a transaction. It is not rolling back even though one of the queries in the transaction has failed. I have debugged affected rows and they are either 0 or 1. Syntax followed:
$cnx = mysql_connect( .. );
mysql_select_db("DB", $cnx);
mysql_query("START TRANSACTION");
mysql_query("BEGIN");
$isrollback = -1;
for (...) // run through query list
{
mysql_query(".... query_i ....");
if(mysql_affected_rows() == 0)
{
$isrollback = 1
}
}
// more queries
if ($isrollback > 0)
mysql_query("ROLLBACK");
else
mysql_query("COMMIT);
Upvotes: 0
Views: 1232
Reputation: 3437
You need to use a transactional database engine. eg INNODB
You are currently using MyISAM which does not support transactions.
This means you cannot start or rollback transactions without changing your DB engine.
MySQL gives instructions on how to convert from MyISAM to INNODB
Upvotes: 1