【发布时间】:2010-08-04 15:59:56
【问题描述】:
目前,我有一个名为DB 的数据库访问类,它使用PDO。然后我有几个子类来访问每个表:
UsersImagesGalleriesTextVideos
当我第一次开始我的项目时,这很好,但现在我不确定它是否那么好,因为我在每个类中使用的每个数据库查询都有一个方法。例如:
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)
嗯,你明白了。我一直在根据需要添加这些方法,在开发中,我首先使用 DB 类:
//Execute a query
DB::query($query);
//Get a single row
$row = DB::getSingleRow($query);
//Get multiple rows
$rows = DB::getMultipleRows($query);
所以,我用我的 DB 类测试查询,然后当它们工作时,我将它们包装在与之相关的类的方法中(图像表的图像类,画廊表的画廊类等)。
我觉得这会随着我稍后添加新功能而不断增长(这可能没问题,但我不确定)。任何人都可以批评我的方法和/或提供替代解决方案吗?
谢谢!
【问题讨论】:
标签: php database model database-abstraction