title: Designing a general database interface in PHP
body: <p>I'm creating a small framework for my web projects in PHP so I don't have to do the basic work over and over again for every new website. It is not my goal to create a second CakePHP or Codeigniter and I'm also not planning to build my websites with any of the available frameworks as I prefer to use things I've created myself in general.</p>
  
  <p>I have had no problems in designing and coding the framework when it comes to parts like the core structure, request handling, and so on, but I'm getting stuck with designing the database interface for my modules.</p>
  
  <p>I've already thought about using the MVC pattern but found out that it would be a bit of an overkill for my rather small project(s).</p>
  
  <p>So the exact problem I'm facing is how my frameworks modules (<code>viewCustomers</code> could be a module, for example) should interact with the database.</p>
  
  <ul>
  <li><p>Is it (still) a good idea to mix in SQL directly into PHP code? (Would be "old way": <code>mysql_query( 'SELECT firstname, lastname(.....)</code>)?</p></li>
  <li><p>How could I abstract a query like the following?</p>
  
  <pre><code>SELECT firstname, lastname FROM customers WHERE id=X
  </code></pre></li>
  </ul>
  
  <p>Would MySQL "helper" functions like</p>
  
  <p><code>$this-&gt;db-&gt;customers-&gt;getBy( 'id', $x );</code> </p>
  
  <p>be a good idea?</p>
  
  <p>I'm not really sure because they tend to become useless when dealing with more complicated queries like the pretty much trivial one above.</p>
  
  <ul>
  <li><p>Is the "Model" pattern from MVC my only real option to solve this?</p></li>
  <li><p>What do you currently use to solve the problems shown above?</p></li>
  </ul>