php connecting to db

diabolo

Community Advocate
Community Support
Messages
1,682
Reaction score
32
Points
48
I have never worked with PHP classes or PDO before. But I think it is time that I start to learn before things get really outdated.

so as I was googling my way trying to find examples/tutorials. two things stood out to me.
1) PDO
2) custom DB classes

I was wondering which one is better to use, providing more security, ease to read/understand, etc.
also, if custom DB classes are better, can someone provide me with a link or attach it to the post?
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
It's not necessarily an either/or situation. Use PDO, because it offers custom queries, integrates with SPL (the PDO drivers use exceptions and PDOStatement implements Traversable, so you can use it in foreach loops). Also, Don't Repeat Yourself (or others). If there's a particular feature you need, use inheritance or class composition to extend PDO. The DB access code should be hidden behind the public interface between the data access layer and the rest of your app; make sure the features you introduce to the db access classes don't belong somewhere else in the data access layer (hint: if the features are to be visible beyond the DAL interface, they don't belong in the DB access code).
 
Top