Designing a general database interface in PHP

Posted by lamas on Stack Overflow See other posts from Stack Overflow or by lamas
Published on 2010-03-17T18:46:35Z Indexed on 2010/03/17 18:51 UTC
Read the original article Hit count: 309

Filed under:
|
|

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.

I have no problems in designing that 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.

I've already thought about using the MVC pattern but thought that it would be a bit of a overkill.

So the exact problem I'm facing is how my frameworks modules (viewCustomers could be a module, for example) should interact with the database.

  • Is it a good idea to write SQL directly in PHP (mysql_query( 'SELECT firstname, lastname(.....))?
  • How could I abstract a query like

    SELECT firstname, lastname FROM customers WHERE id=X
    

Would MySQL helper functions like

$this->db->get( array('firstname', 'lastname'), array('id'=>X) )

be a good idea? I suppose not because they actually make everything more complicated by requiring arrays to be created and passed.

  • Is the Model pattern from MVC my only real option?

© Stack Overflow or respective owner

Related posts about php

Related posts about design-patterns