我在翻译此查询以使用ZF的Zend_Db_Select时遇到一些问题:
SELECT b.id,b.title,b.description FROM memberships AS m JOIN blogs AS b ON b.id = m.blog_id WHERE m.user_id = ? ORDER BY m.created LIMIT 0,30
(此查询有效并返回结果)
成员资格是博客和用户之间的链接表.这很简单id | blog_id | user_id |事务.
这是我到目前为止所拥有的:
// $table = Zend_Db_Table instance,$id = a user id $select = $table->select() ->from(array('m' => 'memberships'),array('b.id','b.title','b.description')) ->join(array('b' => 'blogs'),'b.id = m.blog_id') ->where('m.user_id = ?',(int) $id) ->order('m.created DESC') ->limit(0,30);
这是我得到的(对我来说很奇怪)错误:
#0: Select query cannot join with another table
Occurred on line 211 of
D:\...\library\Zend\Db\Table\Select.PHP
.
谢谢你的帮助.
从表对象中检索时,该语句将限于我认为的那个表. Zend_Db_Table :: select()方法返回Zend_Db_Table_Select对象,该对象是Zend_Db_Select的子类并强加此限制.试试这个:
原文链接:https://www.f2er.com/php/136339.html$db = Zend_Db::factory( ...options... ); $select = new Zend_Db_Select($adapter); $select->from( 'my_table_name' )->join( ...
如果您愿意,以下内容应相同:
$db = Zend_Db::factory( ...options... ); $db->select()->from( 'my_table_name' )->join( ...