That is to say
MySQL opens a connection process at each link, and mysqli runs mysqli multiple times to use the same connection process, thus reducing the server overhead.
When programming, some friends always use new mysqli ('localhost', usenamer ', 'Password', 'databasename'); there is always an error, fatal error: class 'mysqli' not found in D :\...
Isn't the mysqli class included in PHP?
It is not enabled by default. In win, you need to change PHP. ini and remove the ones before php_mysqli.dll. in Linux, You need to compile mysqli.
MySQL is a non-persistent connection function while mysqli is a permanent connection function, that is
MySQL opens a connection process at each link, and mysqli runs mysqli multiple times to use the same connection process, thus reducing the server overhead.
When programming, some friends always use new mysqli ('localhost', usenamer ', 'Password', 'databasename'); there is always an error, fatal error: class 'mysqli' not found in D :\...
Isn't the mysqli class included in PHP?
It is not enabled by default. In win, you need to change PHP. ini and remove the ones before php_mysqli.dll. in Linux, You need to compile mysqli.
Mysqli process-oriented usage:CopyCodeThe Code is as follows: $ conn = mysqli_connect ('localhost', 'root', '000000', 'db _ test') or ('error ');
$ SQL = "select * From db_table ";
$ Query = mysqli_query ($ Conn, $ SQL );
While ($ ROW = mysqli_fetch_array ($ query )){
Echo $ row ['title'];
}
Object-oriented usage of mysqli:Copy codeThe Code is as follows: $ conn = mysqli ('localhost', 'root', '000000', 'db _ test ');
$ SQL = "select * From db_table ";
$ Query = $ Conn-> query ($ SQL );
While ($ ROW = $ query-> fetch_array ()){
Echo $ row ['title'];
}
The connection opened by mysql_pconnect will not be closed (even if mysql_close is called, it will not be closed because it is invalid ),
Similar to the connection buffer pool, if there is a user name from the same machine next time
For connections to the same database, PHP will automatically use the connection established last time, without the need to re-establish a new one.
Advantage: it saves the overhead of establishing a connection to the database every time,
Disadvantage: some memory needs to be wasted and some connections are occupied,
Therefore, if an error occurs when the user's access volume is large, you need to increase the max_connections parameter of MySQL or use mysql_connect () to solve the problem.
First, both functions are used to process databases.
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. View More http://cn.php.net/mysqli
A lot of applications are mysqli transactions.
For example:Copy codeThe 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 ();
}