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); 
有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top