Reputation: 117
This is my (with little pseudo-) code:
$this->db = new mysqli ( $host, $user, $dbpw, $database );
try {
$this->db->mysqli->autocommit(FALSE);
$sql = 'SOME SQL STATEMENT';
$this->db->execute( $sql );
$this->db->mysqli->commit();
}
catch (Exception $e)
{
echo($e);
$this->db->mysqli->rollback();
}
db-class has some enhancements i need but is capable of using the complete mysqli-class.
i have 2 questions.
a. why cant i start the transaction with
$this->db->mysqli->begin_transaction();
its throwing unknown method error. i really dont understand that.
b. do i have to use
$this->db->mysqli->autocommit(TRUE);
?
Upvotes: 4
Views: 4042
Reputation: 30003
a. Because mysqli::begin_transaction
appeared in PHP 5.5.0. Your PHP version is lower it seems.
b. Depends on your requirements. Enabling autocommit
will make MySQL commit transaction automatically and begin another one after executing each SQL statement.
Upvotes: 2