【发布时间】:2011-01-23 00:23:34
【问题描述】:
我想为不同客户的所有表设置一个动态前缀。假设我有客户 A,我的表将是“a_tablename”等。
这一切都很好,所有设置都很顺利,但是,当我在 Zend 框架中运行连接查询时,它从默认表(“表名”)中选择,而不是从前缀表中选择。
这是我的代码的 sn-p:
$select = $hours->select()
->setIntegrityCheck(false)
->from(array('h' => 'hours'), array('id', 'type', 'remark', 'minutes', 'date'))
->join(array('p' => 'projects'), 'h.project_id = p.id', array('description' => 'description', 'order_nr' => 'order_nr'))
->join(array('c' => 'clients'), 'p.client_id = c.id', array('client' => 'name'))
->where($this->db->quoteInto('h.user_id = ?', $userId, 'INTEGER'))
->where($this->db->quoteInto('h.date >= ?', $startDate))
->where($this->db->quoteInto('h.date <= ?', $endDate))
->order(array('h.date', 'h.type'));
$rows = $hours->fetchAll($select);
$this->view->hours = $rows;
此联接采用标准表(客户),其中非联接查询选择客户“a_clients”表。我错过了什么? 这是我的类扩展:
抽象类 Zend_Db_Table 扩展 Zend_Db_Table_Abstract { 函数_setupTableName() { 父::_setupTableName(); $prefix = '堆栈溢出'; // 可能来自配置.. $this->name = $prefix 。 '' 。 $this->_name; } }
(StackOverflow 只是一个固定值,但它用于测试,我从这里复制粘贴它:P)
【问题讨论】:
标签: database zend-framework join zend-db