And during the execution process, if one of the execution fails, all changed operations can be rolled back. If the execution is successful, then this series of operations will be permanently effective. Transactions solve the problem of being out of sync when operating the database problem. At the same time, when executing large amounts of data through transactions, the execution efficiency can be improved a lot.
In PDO, transactions are already very simple. The following is a basic example that demonstrates inserting into a SQLite database 1,000,000 pieces of data, and rollback when an error occurs.
Copy code The code is as follows:
try
{
$conn = new PDO('sqlite:Transactioion.s3db');
$conn->beginTransaction();
for($i=0; $i<1000000; $i++)
{
$conn->exec("insert into [users] values(null,'username')");
}
$conn->commit();
}
catch(PDOException $ex)
{
$conn->rollBack();
}
http://www.bkjia.com/PHPjc/323341.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323341.htmlTechArticleAnd during the execution process, if one of the execution fails, all changed operations can be rolled back. If the execution is successful, then this series of operations will be permanently effective. The transaction is well solved...