Every iteration, the query changes and collects one more record, just to make sure we don’t shoot the same query over and over again and hit MySQL’s cache.
#Pdo mysql movie#
We wrote some code that connects the MySQL database with all three approaches, runs in a loop 200 times for each of them and queries the movie names table. Some of you might argue that it can hurt the experiment’s ability to reflect real performance results, but we believe that as long as we compare apples to apples, we have some good indication to start with. We wanted to have a very basic and clean experiment, without performing any structure changes such as indexing the column. There are 320,000 records in that table now. To set up our experiment, we took IMDB’s titles database and extract around 50MB of data from that into a table called movies, with a column named title. So what’s a better way than to just create an experiment to benchmark mysqli vs pdo vs mysql and see the performance results when running queries through each of them? Experiment Setup & Process But, in this article, we’ll deep dive into one of the aspects - performance. There are a lot to compare between these three, in many aspects such as security, testability, and other. There are three major ways to connect to MySQL databases with PHP - the good old mysql API, and the newer mysqli and pdo. The technology world is all about options, so when looking into the different ways you have to connect to a MySQL database when working with PHP, it’s no different.