Monday, March 9, 2009

Zend_Db component

Zend framework provides some database access components. A common feature of these components is, it can access/query database in OO way. So, it is quite possible that you won't see a whole, integrated sql query in code. Instead, you probably will see a lot of these queries: $where = 'where id = ?'; $db->select('*', $where);

When regarding database query, i am not a supporter of OO. I prefer writing full,whole, or integrated sql, even some times this means duplication. For example, i probably need to use two queries: 1. SELECT * FROM user WHERE id=?; 2.SELECT * FROM user WHERE username = ?. I would like to write them twice, instead of write them in this way: $select = "SELECT * FROM user"; $whereId = " WHERE id=?"; $whereName = " WHERE username=?". Finally, I would just run the whole query by $db->query($sql);

So my model will not extend from any Zend_Db components. And there is no data access object carried with model. I have DAO layer. Instead of calling $user->save(), i would call $daoUser->save($user). And in my dao object, it is always like this: $sql = "SELECT * FROM user"; $db->query($sql);

No comments: