0

I use mysqli for everything. I'm adding features to a small system I built, and some of the examples are pdo. I was about to convert to mysqli to match my system, but I realized it might be less work to change what I've already built to pdo. I've been reading about pdo vs mysqli all over the web.

But here is my question. When will I ever need more than mysqli? PDO offers three major things that mysqli doesn't. Twelve different drivers, named parameters, and prepared statements.

For a web-dev I don't really need the ability to use my web application over 18 database types.

The only major advantage I see is prepared statements.

What are major reasons to switch when the only language I am using is php? Does php even support named parameters now?

Is there even a way to get the number of results from a select using pdo?

stevenmw
  • 689
  • 2
  • 8
  • 15

1 Answers1

1

You managed to confuse everything.

On your statement

  • mysqli does offer native prepared statements support as well
  • named parameters are just actually bloating your code with no purpose. Yet they are very easy to implement manually. There are some people called programmers who can actually program and implement whatever feature they need.
  • twelve different drivers are actually a bubble. Only few of them actually workable and you cannot switch databases by only changing a DSN. You need a higher level of abstraction such as ORM.

On what you have missed

  • mysqli way of handling prepared statements is indeed too complex for a newcomer.
  • as a matter of fact, mysqli is just an API that should never be used as is, but only as a source material for a higher level driver.
  • yet it has a lot of mysql-specific nitty-gritties obviously absent in a generalized driver like PDO

So, in brief

  • If you are going to create a database abstraction library for use with mysql - go for mysqli.
  • If your only idea of using API is to call it's methods directly in the code - then PDO is the only choice as it's already a semi-DAL and it's support for prepared statements is way easier to use.

On your other questions

Does php even support named parameters now?

PHP has nothing to do with named parameters.

Is there even a way to get the number of results from a select using pdo?

You don't need it. Once you have results, you can simply count them.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345