simplyi Posted January 27, 2010 Share Posted January 27, 2010 Hello! I need an advise. I was testing my code and found that when needed Transaction does rollback... Please advise what couple be the problem. 1. Assuming that openConnection() is called and connection with Database is established. public function openConnection() { $this->conn = new mysqli($this->dbhost, $this->dbuser, $this->dbpass,$this->dbname); if( mysqli_connect_errno( ) ) throw new Exception("Could not establish connection with database") ; } 2. Assuming that "record" function is called and the record is INSERTED successfully... and before closing the connection in "record" function I decide to rollback $this->conn->rollback(); but it does not rollback ..... public function record($VO) { $returnValue=0; $sql = "INSERT INTO record(name, phone) " . " values (?,?)"; $this->conn->autocommit(FALSE); $statement = $this->conn->prepare($sql); if(!$statement) throw new Exception($statement->error) ; $statement->bind_param("ss", $VO->name $VO->phone ); $statement->execute(); $returnValue = $statement->affected_rows; ... some other code there that makes me decide to rollback the transaction $this->conn->rollback(); $statement->close(); $this->conn->close(); return $returnValue; } Link to comment https://forums.phpfreaks.com/topic/190053-transaction-does-not-rollback-why/ Share on other sites More sharing options...
Mchl Posted January 27, 2010 Share Posted January 27, 2010 1. Is `record` an InnoDB table? 2. Are there any other queries being run between autocommit(false) and rollback()? Link to comment https://forums.phpfreaks.com/topic/190053-transaction-does-not-rollback-why/#findComment-1002694 Share on other sites More sharing options...
simplyi Posted January 28, 2010 Author Share Posted January 28, 2010 Mchl, thank you very much! The table was not InnoDB and thus did not not support transactions. Thank you! Link to comment https://forums.phpfreaks.com/topic/190053-transaction-does-not-rollback-why/#findComment-1003240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.