Database extension (MySQL, MySQLi, PDO) benchmarks
In the end, the database extension you use doesn't really matter
- Ubuntu 11.10 64-bit
- Intel Core i5 2400 (3.1 GHz)
- 4 GB RAM
- PHP 5.3.6 and MySQL 5.1.58
And... In the end, it doesn't really matter. As long as you don't use mysqli and prepare your queries every single time in a loop. Here is a pretty graph with all the benchmarks I did:
Notice there's a single benchmark that's a lot higher than the others. When you remove the "mysqli_prepare_every_time" line, the difference between the fastest and the slowest method is a lot smaller. Here's a graph of that:
Notice how close together they are? The difference between fastest and slowest around 100ms for 14,000 queries. In the end, this isn't going to be the bottleneck in your application. The bottleneck will be the query that is being run, and not the PHP extension used to run it. So you may as well use PDO and prepared statements because they're awesome .
I didn't include the results from using stored procedures, as they were quite a bit higher than prepared statements. I'm too tired to do it now, but feel free to edit these benchmarks to benchmark a more complex query. The code is available here. My assumption is that with a more complex query, using stored procedures and prepared statements that are reused will have a much bigger impact and definitely beat regular queries.
Edit: Just realised I forgot to label my graphs . The X-axis is iterations and the y-axis is time in milliseconds.