If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Comparing MySQL, mysqli, and pdo for faster website performance

Started by nidhitiwari, Jun 26, 2023, 12:15 AM

Previous topic - Next topic

nidhitiwariTopic starter

Greetings! I have been optimizing a website written in pure PHP 5.6 and MySQL, and it currently runs efficiently with no code issues. However, the website's structure includes multiple queries and a while loop for every "wp structure, home > categories > record" configuration. I plan to launch another site on the same script, but this time, it is expected to handle 1000-2000 hosts, which is about 10-20 times more than the current website. Therefore, I am worried about the issue of speed and load. Can migrating the script to pdo or mysqli improve the website's performance? I don't see the necessity of using Php 7, though.

I have read about pdo and mysqli, but could not find a definitive answer. Hence, my question is, which option is still faster between mysqli and pdo? And for how long exactly? I am interested in numbers. In cases where prepared queries and caching are not used, is it worth considering switching from MySQL at all?
  •  


Greeniintuisp

The key to success lies in metrics gathered from your actual application. To achieve this, you can create a model using a tool like Apache JMeter, recording a typical client session and running it through various providers multiple times.

One approach is to use a tool like Apache JMeter, where you can create a model by recording a standard client session and executing it on different providers multiple times for accurate results.
  •  

drunken

In order to ensure the longevity of your website, you'll eventually need to transition away from PHP5 to a newer version as support for outdated versions will eventually expire. This shift will also require leaving behind the mysql library.

Transitioning to a newer version of PHP can seem daunting, but it's important to keep in mind that this change is essential for maintaining the security and performance of your website. While the mysql library has been widely used in the past, there are now more advanced database systems available that offer greater functionality and security features. It's crucial to plan ahead and make the necessary updates to your website to ensure its continued success.
  •  

kyouxngofi

Did mysql become mysqli, and will there be a mysql-? pi of some sort causing the need to constantly adjust the site? This is why they use PDO to avoid being tied to li or pi.


The speed of queries is influenced not only by the number of queries, but also by which columns are quickly indexed and which ones are not. Using LIMIT 1 for a single line can increase speed. In general, fewer cycles lead to faster results. To optimize performance, try writing optimized code without unnecessary operations and selecting only what is necessary. Caching and compressing (images, css, js) can also improve speed, as can using fast operators instead of slow ones.
  •  

alexfernando

Migrating your website to either PDO or MySQLi can potentially improve performance compared to using the deprecated MySQL extension in PHP 5.6. Both PDO and MySQLi provide improved security features and support for newer versions of MySQL.

However, when it comes to performance, the choice between PDO and MySQLi is not significant. Both extensions offer similar performance characteristics, and the difference between them is often negligible.

To get more specific numbers about the performance, it would be best to conduct your own benchmarking tests based on your specific application and workload. This will help you evaluate the performance difference between PDO and MySQLi in your particular scenario.

Regarding PHP 7, it is highly recommended to consider upgrading to PHP 7.x as soon as possible. PHP 7 introduced significant performance improvements over PHP 5.6, with up to 2x faster execution speed and reduced memory usage. It also provides better error handling, improved security features, and many new language features. Upgrading to PHP 7.x can lead to a substantial performance boost for your website.

In terms of switching from MySQL to other databases, it depends on your specific requirements and the capabilities of the alternative databases. MySQL is a popular and widely used database that performs well in most scenarios. However, if you have specific use cases or requirements that are better suited for another database, such as PostgreSQL or MongoDB, it might be worth considering a switch.


When it comes to comparing MySQL, MySQLi, and PDO for website performance, there are a few key factors to consider:

1. Speed: In terms of raw performance, MySQLi and PDO tend to be faster than the older MySQL extension because they provide more efficient ways to interact with the database. However, the difference in speed between MySQLi and PDO is usually marginal.

2. Prepared Statements: Using prepared statements can significantly improve performance by reducing the overhead of parsing and optimizing SQL queries. Both MySQLi and PDO support prepared statements, allowing you to bind parameters and execute queries more efficiently.

3. Flexibility and Database Support: PDO offers a more versatile API since it supports multiple databases, including MySQL, SQLite, PostgreSQL, and more. If you anticipate the need to switch to a different database in the future, PDO provides better flexibility. MySQLi is specific to MySQL databases but offers some additional features like asynchronous querying, which can be beneficial in certain scenarios.

4. Security: All three extensions (MySQL, MySQLi, and PDO) offer methods to prevent SQL injection attacks. However, PDO and MySQLi have stronger built-in support for prepared statements and parameter binding, making it easier to write secure code.

Here are a few more points to consider when comparing MySQL, MySQLi, and PDO for website performance:

1. Object-Oriented vs. Procedural Style: MySQLi offers both procedural and object-oriented styles, giving you the flexibility to choose your preferred coding style. PDO, on the other hand, is inherently object-oriented. The choice between these styles depends on your personal preference and the coding conventions followed in your project.

2. Code Readability and Maintainability: PDO often provides a cleaner and more concise code syntax compared to MySQLi. Its uniform API makes it easier to understand and maintain code, especially when working with multiple databases or switching between different database systems.

3. Community and Support: MySQLi has been around for a longer time and has a larger user community, which means you can find more code examples, tutorials, and community support specific to MySQLi. PDO also has a significant user base but may have fewer resources available for some specific database systems.

4. Compatibility and Portability: If your website needs to be deployed on multiple platforms or servers with different configurations, PDO can offer better compatibility. Since PDO supports multiple database systems, it allows you to switch databases more easily without rewriting significant portions of your code.

5. Development Effort and Time: Migrating from the deprecated MySQL extension to either MySQLi or PDO will require some effort and time. However, the migration process is relatively straightforward and worth it for the improved performance, security, and future compatibility benefits.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...