I am using PDO to make the connection to the DB.
I was wondering how should i structure it using the MVC pattern.
Currently i have it like this:
What do you think about it?
Is it ok? Should i place DB, Model and MySQLDB in another subfolder?
Thanks.
You should have a look at DAO design pattern http://en.wikipedia.org/wiki/Data_access_object. It allows for the separation of Models and Database interface, which will be very useful if at some point you want to switch the database.
You might also want to read more about it in this article http://www.sitecrafting.com/blog/php-patterns-part-ii/
It’s a matter of preference, but I would structure them in the following manner
Modelwould contain all the Model classes with Business Logic in themDAOwould contain all the generic database SQL scripts and connectionsConfigwould contain all the configuration scriptsViewall the viewsNot sure what the
DB.phpdoes, so not sure where to place it.Steve was asking in the comment about the difference between
Model/User.phpandDAO/MySQLDB/User.php, hope this example will illustrate it welland
Have a look at how the biggest frameworks structure their folders i.e. Zend Framework example is here http://framework.zend.com/manual/en/project-structure.project.html
They usually thought long about the set up, and most of the developers are familiar with it, so if you have a new hire, they will be able to find their way around the custom built system quicker than they would otherwise.