Should project that will always use MySQL use PDO?
I have created a p开发者_StackOverflow社区roject 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?
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.
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.
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.
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.
精彩评论