Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi Larry - do you have a recommendation for whether it's better to use PDO vs. MySQLi for working with databases in PHP?

 

It looks like you go exclusively with MySQLi in your books and in fact don't mention PDO at all.

 

Do you consider MySQLi best practice, and if so, is that the case for both procedural and object-oriented programming?

Link to comment
Share on other sites

Thanks for the good questions. I don't consider MySQLi to be a best practice overall, but it's something everyone is going to need to learn to use, which is why it's in the book and PDO isn't. Also, PDO uses an OOP interface, which the book does not, prior to the 4th edition.

 

PDO is wonderful and very useful. However, and I'm probably in the minority here, but I don't see a lot of benefit to using a data-access abstraction layer (or a database abstraction layer) unless you know the application will be ported to different database applications. I've been doing this for 12 years now and I've never once switched the underlying database. If you're creating something intended to work with multiple database applications, or you want that capability, fine, but for about 95% of all applications, it seems that we're using MySQL and we're going to use MySQL and I don't see the benefit of adding an abstraction layer in there. But, as I said, I'm probably in the minority on this one.

Link to comment
Share on other sites

Thanks for the quick reply. That's my opinion as well - it seems like it would be extremely rare to switch database systems for a site that's already been developed.

 

There are four main considerations I have for choosing whether to focus my studies on MySQLi or PDO:

 

1. Performance. I've seen a few benchmarks that show MySQLi is faster than PDO. Advantage: MySQLi

 

2. Employability: I'd rather master the approach that's most likely to keep me employed. Advantage: Don't know

 

3. Scalability: If the field is gradually moving toward standardizing on PDO, I'd just assume make it my standard as well. Advantage: PDO

 

4. OOP: I had assumed the choice between MySQLi vs. PDO came down to procedural vs. OOP. However, after reading further, it doesn't seem this straightforward. Advantage: Don't know

 

Any thoughts on these or other considerations from anyone?

Link to comment
Share on other sites

In terms of performance, there's also this new mysqlnd: MySQL Native Driver. I believe it performs better than the old MySQL driver. If installed, MySQLi will take advantage of it; I'm not sure if PDO will or not.

 

In terms of employment, surely there's an argument to learning PDO, even if you don't regularly use it.

 

In terms of OOP, MySQLi can be used either procedurally or OOP; PDO can only be used with OOP.

 

I'm always a advocate of learning new things and learning more, so I wouldn't want to suggest that people shouldn't check it out, I'm just not convinced it's The Next Big Thing that everyone should use all the time.

Link to comment
Share on other sites

 Share

×
×
  • Create New...