Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You shouldn't have almost any SQL in your database access layer as it should be merely abstract the communication with the database regardless of what actual SQL it's communicating.</p> <p>In the now famous MVC pattern, your business logic <em>is</em> what typically contains the SQL which forms the Model layer.</p> <p>Putting all these "religious" definitions aside, what you have now is moderately normal, to end up with piles of SQL. SQL has to exist, somewhere. Depending on your priorities and performance requirements here is what I would do (ordered by performance compromise):</p> <ol> <li><p>If there is noticeable repetition in the SQL, I'd throw in a quick refactoring iteration to hide all the common SQL inside methods. The methods do not necessarily have to execute it, but just build it. It all depends on your application and in which way the SQL is complex. If you don't have an underlying layer which does the actual communication with the database, maybe part of the refactoring could be to add it.</p></li> <li><p>I'd consider a Query builder. Which is a very good balance between performance and flexibility. You can only find a query builder as part of an ORM or Database Access layer (like Zend_Db and its sub components), Propel and/or Doctrine. So you can either port a query builder off one of those to your project without using the whole layer (which really shouldn't be hard as all of them are PDO-based). This shouldn't add any noticeable performance issues.</p></li> <li><p>I'd consider the Doctrine ORM. This has considerable effect in performance though. You will end up with very maintainable code however. </p></li> </ol> <p>Finally, I'd never consider putting the SQLs into Resources or something like that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload