title: Why should I abstract my data layer?
body: <p>OOP principles were difficult for me to grasp because for some reason I could never apply them to web development. As I developed more and more projects I started understanding how some parts of my code could use certain design patterns to make them easier to read, reuse, and maintain so I started to use it more and more.</p>
  
  <p>The one thing I still can't quite comprehend is why I should abstract my data layer. Basically if I need to print a list of items stored in my DB to the browser I do something along the lines of:</p>
  
  <pre><code>$sql = 'SELECT * FROM table WHERE type = "type1"';'
  $result = mysql_query($sql);
  
  while($row = mysql_fetch_assoc($result))
  {
      echo '&lt;li&gt;'.$row['name'].'&lt;/li&gt;';
  }
  </code></pre>
  
  <p>I'm reading all these How-Tos or articles preaching about the greatness of PDO but I don't understand why. I don't seem to be saving any LoCs and I don't see how it would be more reusable because all the functions that I call above just seem to be encapsulated in a class but do the exact same thing. The only advantage I'm seeing to PDO are prepared statements.</p>
  
  <p>I'm not saying data abstraction is a bad thing, I'm asking these questions because I'm trying to design my current classes correctly and they need to connect to a DB so I figured I'd do this the <em>right</em> way. Maybe I'm just reading bad articles on the subject :)</p>
  
  <p>I would really appreciate any advice, links, or concrete real-life examples on the subject!</p>