The principles of OOP were difficult for me because for some reason I could never apply them to web development. As I developed more and more projects, I began to understand how some parts of my code can use certain design patterns to make them easier to read, reuse, and maintain, so I started using it more and more.
The only thing I still can not understand is why I should abstract my data layer. Basically, if I need to print a list of elements stored in my database into a browser, I do something like:
$sql = 'SELECT * FROM table WHERE type = "type1"';'
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
echo '<li>'.$row['name'].'</li>';
}
I read all of these How-Tos or articles preaching about the greatness of PDO, but I donβt understand why. I donβt seem to save LoCs, and I donβt see how it will be used more than once, because all the functions that I call above just seem to be encapsulated in the class, but they do the same. The only advantage that I see in PDO is prepared statements.
I am not saying that data abstraction is bad, I ask these questions because I am trying to develop my current classes correctly and they need to connect to the database, so I decided that I would do it the right way. Maybe I'm just reading bad articles on this topic :)
I would really appreciate any advice, links or concrete real-life examples on this subject!
source
share