duanmin0941 2010-10-01 13:32
浏览 29
已采纳

哪些数据库模式(ORM,DAO,Active Record等)用于小型/中型项目?

I writing real estate web site with basic function for choosing and ordering realty.

It is small/simple project, but I want to write it in way, so in future I, or other developers, can turn it into medium business app without rewriting it from scratch.

So what kind of patterns could you advice me to use for dealing with database?

For now I have this:

class db_DBConnection
{
    // basic singleton pattern here...
}

// primary class to be extende by other table DAOs
abstract class db_Table
{
protected $table;
protected $order_by;

/**
 * Executes specified query with prepared statements
 * returns statement object, which can fetch data.
 * 
 * @param $sql - SQL query to execute
 * @param $params - bind values to markers through associative arrays
 */
protected function executeQuery($sql, $params = null)
{
    $dbh = db_DBConnection::getConnection();
    $stmt = $dbh->prepare($sql);
    // binds values to markers and executes query
    $stmt->execute($params);
    return $stmt;
}

/**
 * @param id - id of row to retrieve from database
 *
 * It sends SQL query and id to executeQuery
 * function returns associative array, representing
 * database row.
 */
public function find($id)
{
    $sql = 'SELECT * FROM ' . $this->table . ' WHERE id=:id LIMIT 1';
            // bind id
    $params = array( ':id' => $id );
    // execute and return associative array
    return $this->executeQuery($sql, $params)->fetch(PDO::FETCH_ASSOC);
}

public function findAll($quantity, $where)
{
// Returns array of
// associative arrays of table rows :)
// TODO: write this function
}

abstract protected function insert();

abstract protected function update();

abstract protected function delete();

    // ...
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 MATLAB 调用comsol如何加速设计?
      • ¥15 echarts地图添加点击事件
      • ¥15 不知道带什么标题好随便搞一个吧
      • ¥15 ffmpeg 图片合成视频
      • ¥15 软科大学爬取获取所有数据
      • ¥15 如何修改损失函数以及代码讲解
      • ¥15 有偿咨询!!程序的小数点怎么取到后四位啊!
      • ¥15 IRS智能反射面相关文章代码
      • ¥15 landsat5的两幅影像镶嵌前波段是123457,为什么镶嵌后波段变成了123456?
      • ¥15 关于#matlab#中fmincon函数如何处理约束问题?