Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's all start with <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" rel="nofollow">Separation of concerns</a> and nowadays the most popular architecture for web applications is <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow">Model-View-Controller</a> (you don't need to invent one, you may use some of the existing PHP frameworks, each of them is bundled with some kind of <a href="http://en.wikipedia.org/wiki/Object-relational_mapping" rel="nofollow">ORM</a>). </p> <p>Since you are asking about isolating the database code, the models is the first thing you should learn from the MVC paradigm. All operations on the data, including any business logic and calculations, all DB operations, go to the model classes. There are different way you may structure them. One popular pattern is the <a href="http://en.wikipedia.org/wiki/Active_record_pattern" rel="nofollow">Active Record</a> - literally a class per table. I'm not a big fan of this - you may create classes after your logical entities (user, game, etc), and they may operate on multiple tables. But those classes may be build upon Active Record anyway.</p> <p>If you are working with existing code, you can start with isolating the queries in objects, so all code that work with the database is in one place - then you can start restructure objects to follow the chosen architecture : User objects works with the users table, and so on... After you separated the DB code in objects, you can easily switch to PDO or other db-implementations and protect from SQL injections.</p> <p>In the end I'd like to recommend few books: <a href="http://rads.stackoverflow.com/amzn/click/0201485672" rel="nofollow">Refactoring</a> - the best book about how to turn legacy code in beautiful OO solutions</p> <p><a href="http://rads.stackoverflow.com/amzn/click/0321127420" rel="nofollow">Patterns of enterprise application architecture</a> - hard to read but has a lot of useful info</p> <p><a href="http://rads.stackoverflow.com/amzn/click/B000XPRRVM" rel="nofollow">Implementation Patterns</a> - unlike books on Design Patterns, this is focused on the small decisions, literally on each line of code</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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