Jump to content

Performance: PDO vs. MySQLi vs. MySQL ?


bachx

Recommended Posts

Alright guys, I see people recommending prepared statements (PDO/MySQLi) and saying that they are way to go these days.

 

However upon doing a bit more research, I've found that prepared statements, PDO in particular, is lacking in terms of performance, especially using SELECT statements. 

 

Now I'm starting a new project, which is basically a text based game with lots of queries and DB interaction, so I'm really interested in knowing what's the best approach for me.  I was leaning towards PDO but I don't want it crawling my server under heavy load.

 

I appreciate any advices or first hand experiences on this.

Link to comment
Share on other sites

It's not always about the performance; PDO was designed to provide a single interface between different database platforms. This may not be a concern for you, but for larger businesses or sites that use multiple platforms it's a huge bonus.

 

Prepared statements are faster than normal queries because they're optimized for repeat queries with different parameters - a query run once will not see the benefit. If prepared statements are not supported for a particular database engine, PDO will emulate the behaviour.

 

The MySQLi vs. MySQL extensions is a heavily disputed topic. MySQLi offers more functionality like an optional object orientated interface, however the results between performance vary on the type of query, set-up of MySQL, etc.

 

It's kind of up to your own initiative to choose the right extension for you.

Link to comment
Share on other sites

Thanks for the reply. So if I'm looking for pure performance, MySQL is the way to go? For those that used both PDO and MySQL, is PDO noticeably slower in actual web performance? I can see the advantage of prepared statements with repeated queries, however it's somewhat situational.

 

 

Link to comment
Share on other sites

I use PDO and PostgreSQL on Linux servers for fairly data intensive processes and analysis and performance has always been acceptable.  The advantage to prepared statements, regardless of PDO or another extension is primarily repeated queries will perform better.  In addition, the arguments will also be correctly escaped by the database wrapper as well; this eliminates your need as the developer to insert mysql_real_escape_string() calls all over the place (at least this is true with PDO/PostgreSQL).

 

It's not always about the performance; PDO was designed to provide a single interface between different database platforms. This may not be a concern for you, but for larger businesses or sites that use multiple platforms it's a huge bonus.

This is only true to some extent.  Once you start using SQL syntax supported by only one flavor you still end up writing if-else or switch statements.  However at least the method names and error handling can be somewhat consistent.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.