Performance Comparison Between Pdo-MySQL and Mysqli In the Mysql database of PHP

Source: Internet
Author: User

We know that LAMPLinux + Apache + Mysql + PHP) is a very common WEB server combination. PHP has manyMySQL databaseTo facilitate our use, for example:Pdo-Mysql,MysqliAnd so on. Which method has the best performance? In this article, we compare the performance of the above Connection Methods:

1. Create a Mysql database, create an InnoDB table, and refer to the core table of a project.) then, use the stored procedure to generate 1 million pieces of data.

2. In a PHP environment, each access will randomly query a piece of data in the database.

3. verify the correctness of the query results after the access is completed.

Pdo-Mysql persistent connection $ dbh = new PDO (......, Array (PDO: ATTR_PERSISTENT => true ));

Pdo-Mysql short connection $ dbh = new PDO ($ host, $ username, $ password );

Mysqli $ dbh = new mysqli ($ host, $ username, $ password, $ dbname, $ port );

Mysqli_connect $ dbh = mysqli_connect ($ host, $ username, $ password, $ dbname, $ port );

$ Dbh = mysql_connect ($ host, $ username, $ password );

Conclusion:

1. Use the persistent connection mode of Pdo-Mysql to achieve optimal performance;

2. Mysql has better performance than Pdo-Mysql instant connection;

3. There is no significant difference in the real-time connection performance of Pdo-Mysql compared with the "built-in" method.

Appendix: Figure of transactions per second between Pdo-Mysql and Mysqli:

Appendix, the memory usage diagram of the Web server during the corresponding time period:

We can see from the two figures above:

1. The reason why Pdo-Mysql is faster than Mysqli is that Pdo-Mysql has fewer database operations than Mysqli;

2. In the Pdo-Mysql persistent connection test, the Web server memory continues to rise.

After a simple check, the httpd process memory of the Aapche service is increased, and the module name is displayed as [anonymous]. The reason will be further checked later)

From the perspective of performance, the persistent connection performance of Pdo-Mysql is the best, but the disadvantages are still to be verified.

This article introduces the performance comparison between MySQL and Mysql In the MySQL database in PHP. I hope this introduction will help you gain some benefits!

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.