This article provides a detailed analysis of the differences between mysql and mysqli in php. For more information, see the following two functions.
First, mysqli connections are permanent connections, while mysql does not. What does it mean? Mysql will re-open a new process whenever it is used for the second time, while mysqli only uses the same process, which can greatly reduce the pressure on the server.
Secondly, mysqli encapsulates some advanced operations such as transactions and many available methods in the database operation process.
A lot of applications are mysqli transactions.
For example:
The code is as follows:
$ Mysqli = new mysqli ('localhost', 'root', '', 'DB _ Lib2Test ');
$ Mysqli-> autocommit (false); // start transaction
$ Mysqli-> query ($ sql1 );
$ Mysqli-> query ($ sql2 );
If (! $ Mysqli-> errno ){
$ Mysqli-> commit ();
Echo 'OK ';
} Else {
Echo 'err ';
$ Mysqli-> rollback ();
}