Home >Backend Development >PHP Tutorial >How Do MySQLi Transactions Begin and End?
Transactions in MySQLi: Initiation and Termination
Question:
Can you clarify whether transactions in MySQLi commence with $mysqli->autocommit(FALSE) and conclude with $mysqli->commit() based on the provided code sample?
Answer:
Yes, the provided understanding is accurate. Transactions in MySQLi initiate with the $mysqli->autocommit(FALSE) command and terminate with $mysqli->commit(). During a transaction, all database operations are grouped as a single unit.
Additional Explanation:
The autocommit function in MySQLi controls whether queries are automatically committed to the database. When set to TRUE (the default), each query is committed individually. By setting autocommit to FALSE, you open a transaction window where multiple queries can be executed before being committed as a complete unit with $mysqli->commit().
In the example code provided:
The above is the detailed content of How Do MySQLi Transactions Begin and End?. For more information, please follow other related articles on the PHP Chinese website!