• 7th August 2006 - By Vinu Thomas

    Here’s an interesting article showing benchmarks between the various libraries used to query MySQL databases. It looks like the mysql and mysqli libraries work much faster than PDO.

    Extension Req/Sec
    mysqli
    164
    mysql
    162
    PDO
    88
    mysqli (prepared)
    86
    PDO (prepared)
    81

    Link: PHP and MySQL, the future

  • 15 Comments to “Benchmark mysql, mysqli, pdo in PHP”

    • stefan on August 7, 2006

      of course, it isn’t *that* weird that PDO is slower. PDO is, as far as I can see it, more of a complete database abstraction layer than just an interface to mysql. mysql and mysqli are just focussing on mysql connectivity.

      Thus, when writing an application that is 100% guaranteed to always use mysql, using one of those interfaces will work better than PDO. But when you need the flexibility of a database abstraction layer, PDO will make your code much more solid and portable.

    • stefan on August 7, 2006

      of course, it isn’t *that* weird that PDO is slower. PDO is, as far as I can see it, more of a complete database abstraction layer than just an interface to mysql. mysql and mysqli are just focussing on mysql connectivity.

      Thus, when writing an application that is 100% guaranteed to always use mysql, using one of those interfaces will work better than PDO. But when you need the flexibility of a database abstraction layer, PDO will make your code much more solid and portable.

    • vinuthomas on August 7, 2006

      I was under the impression that since PDO is a compiled extension for PHP, the performance would be much faster than using the Pear DB class for database abstraction. But a 50% performance drop was not what I had in mind.

    • vinu on August 7, 2006

      I was under the impression that since PDO is a compiled extension for PHP, the performance would be much faster than using the Pear DB class for database abstraction. But a 50% performance drop was not what I had in mind.

    • stefan on August 7, 2006

      I don’t think this compares PDO to Pear DB. It just compares PDO with executing a regular query (I didn’t read it through and through, so I might be wrong). Comparing PDO to Pear DB will probably give different results.

    • stefan on August 7, 2006

      I don’t think this compares PDO to Pear DB. It just compares PDO with executing a regular query (I didn’t read it through and through, so I might be wrong). Comparing PDO to Pear DB will probably give different results.

    • vinuthomas on August 7, 2006

      Yep – They don’t compare PDO with PEAR DB. I guess that’s a good benchmark to take if we’re looking at database abstraction for PHP.

    • vinu on August 7, 2006

      Yep – They don’t compare PDO with PEAR DB. I guess that’s a good benchmark to take if we’re looking at database abstraction for PHP.

    • Stefan Koopmanschap on August 8, 2006

      I wouldn’t be interested in that, but I dislike the whole PEAR project bigtime. The only thing I liked, PHPUnit, has split out of the project recently, so it’s no good.

      I’d be interested in a benchmark between PDO and adoDB though

    • vinu on August 8, 2006

      That’s a good suggestion. Let me see if I can whip up some benchmarks :)

    • karl on August 31, 2006

      really interesting articles, and i really believe that mysql and mysqli libraries work much faster than PDO.!

      good blog!

    • Name on March 17, 2007

      Pdo may be slower but mysql\mysqli only allow connections to mysql and this does not cut it when you want your application to be able to support multiple databases.

      Correct me if I am wrong but dont most abstraction layers get their performance from using extensions such as mysql\mysqli\pgsql. These are faster than pdo and would probably explain the benchmarks combined with a few other things I wont get into

    • Wayne on March 14, 2009

      Thanks a million!

      I was about to start a big project and was pondering over whether I should use PDO instead of Mysqli! I think I’ll just stick to MySqli now!

    • Schattenjaeger on February 10, 2010

      Don’t use OLD(!!) benchmarks, this benchmark is from 2006 so mysql, mysqli and PDO got many changes.

      BTW: You shouldn’t rely on the performance of database-functions/methods. The most problems will always be the codebase around it and your database model (and maybe your mysql-settings)!

    • vinu on February 10, 2010

      Schattenjaeger, Yep – this is an old post on my blog from 2006.

    Leave a Reply