Jump to content

Transaction does not rollback... why?


simplyi

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.