Designing a general database interface in PHP
- by lamas
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?