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:
Copy codeThe 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 ();
}