And, in the course of execution, if one of the executions fails, you can roll back all the changed operations. If the execution succeeds, the sequence of operations will be permanently valid. The transaction solves the problem of being out of sync when manipulating the database. At the same time, the execution efficiency can be much higher when the transaction executes the large amount of data.
In PDO, the transaction has become very simple. The following basic example demonstrates inserting 1 million data into the SQLite database and rolling back when an error occurs.
Copy the Code code 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 ();
}
The above describes the transactional PHP in the use of the transaction in PDO, including the transactional aspects of the content, I hope that the PHP tutorial interested in a friend helpful.