Currently, I have a database access class named DB
, which uses PDO
. I Then have a handful of sub-classes for accessing each table:
Users
Images
Galleries
Text
Videos
This was nice when I first started my project, but now I'm not sure if it's that great, as I have a method for each database query that I use within each of these classes. For example:
Images::insertNew($filename)
Images::getTotalInGallery($galleryId)
Images::getAllInGallery($galleryId, $fetchStyle)
Images::updateDescription($imageId, $description)
Images::updateGallery($imageId, $galleryId, $orderNum)
Images::getSingle($imageId)
Images::getFilename($imageId)
Images::getImageIdByFilename($filename)
Galleries::getNameById($galleryId)
Galleries::getAll()
Galleries::getMaxImages($galleryId)
Galleries::checkIfExists($galleryId)
Galleries::createNew($galleryName)
Galleries::getById($galleryId)
Galleries::delete($galleryId)
Well, you get the idea. I have been adding these methods as the need for them arises, and in development, I start by just using the DB
class:
//Execute a query
DB::query($query);
//Get a single row
$row = DB::getSingleRow($query);
//Get multiple rows
$rows = DB::getMultipleRows($query);
So, I test queries with my DB class, then when they are working, I wrap them in a method of the class that is related to it (Image class for images table, Galleries class for galleries table, etc.).
I feel like this will keep growing and growing as I add new features later on (which may be OK, but I'm not certain). Can anybody critique my method and/or provide alternative solutions?
Thanks!