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
Model/User.php
DAO/MySQLDB/User.php
DAO/MySQLDB.php (old DB.php)
Config/DatabaseConfig.php
View/Index.php
MySQLDB.php
Model
would contain all the Model classes with Business Logic in them
DAO
would contain all the generic database SQL scripts and connections
Config
would contain all the configuration scripts
View
all the views
Not sure what the DB.php
does, so not sure where to place it.
Steve was asking in the comment about the difference between Model/User.php
and DAO/MySQLDB/User.php
, hope this example will illustrate it well
class Model_User
{
public function hashPassword($password)
{
$salt = SALT_STRING;
return hash("sha512", $password.$salt);
}
public function getById($id)
{
$id = (int) $id;
$db_data = new MySQLDB_User();
$db_data->getById($id);
return $this;
}
}
and
class MySQLDB_User
{
public function getById($id)
{
$sql = "SELECT * FROM `users` "
." WHERE `id` = \"" . $this->_db_connection>real_escape_string($id)
. "\" LIMIT 1";
$result = $this->query($sql);
$this->_parseRow($result);
return $this;
}
}
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.