Everything I’ve read so far about PDO (PHP Data Objects) is almost too good to be true.
I mean:
- Its faster then mysql or mysqli.
- It has the same syntax for multiple database drivers.
- with prepared statements it is secure for SQL injection.
- you can fetch data directly into a object.
But what are the disadvantages of PDO?
I use PDO every day, and that’s for a reason. I did write a wrapper over it though, because the default PDO instance does things I don’t like (e.g. fail silently), and the API could’ve been a whole lot better. Configuration with constants is just not my default approach. Also, I’ve created some convenience methods.
Is it? I don’t know where you picked this up, and it might well be true, but I haven’t heard of PDO being faster than the native MySQL libraries.
Sort of. I use PostgreSQL a lot, and the code is different from when you’re working with MySQL. This makes sense though, as PostgreSQL works with named sequences, while MySQL works with “auto increment”, which is a sequence per table. There are differences between databases that PDO can not abstract, even if it’s just for database access.
You can prepare statements with mysqli too, so I don’t see this as a definitive upside. I do generally use prepared statements though, and I like the :field syntax PDO provides.
The API is less than intuitive for me, I think the API of mysqli makes more sense. Nevertheless, if you write a wrapper for it yourself, it’s a very decent library. Here’s the wrapper I wrote to make using PDO a little bit more sane, there are many more examples drifting on the internet though.
EDIT: Oh, and James Anderson is right; it has poor Oracle support. I don’t use Oracle, so I don’t see that as a huge downside though.