The difference and usage explanation of Mysql and mysqli _mysql

Source: Internet
Author: User
Other words

MySQL each link will open a connected process and mysqli run mysqli multiple times will use the same connection process, thereby reducing the cost of the server

Some friends use the new mysqli (' localhost ', usenamer ', ' Password ', ' DatabaseName ') when programming, and always error, Fatal error:class ' mysqli ' not found In D:\ ...
is the Mysqli class not PHP-led?

Not the default to open, win under to change php.ini, remove Php_mysqli.dll before;, Linux to the mysqli compiled into

MySQL is a non-mysqli connection function and is a permanent connection function, which means

MySQL each link will open a connected process and mysqli run mysqli multiple times will use the same connection process, thereby reducing the cost of the server
Some friends use the new mysqli (' localhost ', usenamer ', ' Password ', ' DatabaseName ') when programming, and always error, Fatal error:class ' mysqli ' not found In D:\ ...
is the Mysqli class not PHP-led?

Not the default to open, win under to change php.ini, remove Php_mysqli.dll before;, Linux to the mysqli compiled into
Process-oriented use of mysqli:
Copy Code code as follows:

$conn = Mysqli_connect (' localhost ', ' root ', ' 123 ', ' 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 use of mysqli:
Copy Code code as follows:

$conn = mysqli (' localhost ', ' root ', ' 123 ', ' db_test ');
$sql = "SELECT * from db_table";
$query = $conn->query ($sql);
while ($row = $query->fetch_array ()) {
echo $row [' title '];
}

The Mysql_pconnect open connection does not close (even if the call Mysql_close does not close because it is not valid),
Similar to the connection buffer pool, if the next time there is a same user name from the same machine
For a connection to the same database, PHP automatically uses the previously established connection without having to re-establish one.
Benefits: Eliminates the cost of establishing a connection to the database each time,
Disadvantage: It is necessary to waste some memory, occupy some connections,
So if the user visit a large amount of time will be wrong, to the MySQL max_connections parameters, or use mysql_connect () to solve the problem.

first of all, two functions are used to process db.

First, the MYSQLI connection is a permanent connection, and MySQL is a non permanent connection. What does that mean? The MySQL connection will reopen a new process whenever it is used for the second time, and Mysqli will only use the same process, which can greatly reduce server-side pressure.
Second, mysqli encapsulates some advanced operations, such as transactions, while encapsulating many of the methods available during the DB operation. Specific View Http://cn.php.net/mysqli

The most widely used place is the mysqli business.
Like the following example:
Copy Code code as follows:

$mysqli = new mysqli (' localhost ', ' root ', ', ', ' db_lib2test ');
$mysqli->autocommit (FALSE);//start things
$mysqli->query ($sql 1);
$mysqli->query ($sql 2);
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.