Martin Thoma
Martin Thoma

Reputation: 136409

Should project that will always use MySQL use PDO?

I have created a project which uses a MySQL-database in a very basic way. This means I only use SELECT, INSERT, UPDATE and DELETE. No joins, no table creation. Most queries are SELECTs and most of the time I only select some rows of one record.

I'm also quite sure that this project will always use MySQL.

Now I've heard about PDO and some people seem to think that it's in general a good idea to use it. According to php.net "PDO provides [only] a data-access abstraction layer".

Is there any reason why a project which will always use MySQL should use PDO? Any reason why it might be a bad idea to use PDO in such a project?

Upvotes: 2

Views: 273

Answers (4)

Samia Ruponti
Samia Ruponti

Reputation: 4038

First of all, PDO is mostly used for object oriented programming. It is also a lot safer and faster than MySQL. Since you are accessing data for CRUD (create,read, update,delete) it is actually more efficient than MySQL.

Only problem I see is to install the PDO driver, but it is installed on most servers now.

So, if you're going to use OOP, the you must use PDO.

Upvotes: 0

Lepidosteus
Lepidosteus

Reputation: 12037

There is no reason why you should not use it.

You can also be totally safe not using it, just remember to use the modern extension mysqli and not mysql, and use parameterized queries instead of the utter mess that is string concatenation and mysql_real_escape_string().

The reason why you should be using PDO, however, is that it will teach you how to use an interface database that will give you the generic knowledge to work on any other database in your future projects. In other words, it will teach you to differentiate "ask some data from the database" from "how exactly does this particular database need to be called". Again, use parameterized queries with it.

Upvotes: 1

Ariel
Ariel

Reputation: 26753

If you have no joins why are you using a relational database in the first place? You just need a key/value store.

I usually don't use pdo for MySQL specific projects.

Upvotes: 0

Matteo Riva
Matteo Riva

Reputation: 25060

It's always a good idea, if only for prepared statements and bound parameters.

PDO supports different database drivers but does not provide database abstraction, it just provides a consistent interface to accessing data. There is really no drawback in using it, and mysql_* functions should just be dropped.

Upvotes: 4

Related Questions