Differences between MySQL and mysqli and usage instructions

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.