我有这个问题:
SELECT g.title, g.asin, g.platform_id, r.rank
FROM games g
INNER JOIN ranks r ON ( g.id = r.game_id )
ORDER BY r.rank DESC
LIMIT 5`
Run Code Online (Sandbox Code Playgroud)
现在,这是我的JOIN使用,Zend_Db_Select
但它给了我数组错误
$query = $this->select();
$query->from(array('g' => 'games'), array());
$query->join(array('r' => 'ranks'), 'g.id = r.game_id', array('g.title', 'g.asin', 'g.platform_id', 'r.rank'));
$query->order('r.rank DESC');
$query->limit($top);
$resultRows = $this->fetchAll($query);
return $resultRows;
Run Code Online (Sandbox Code Playgroud)
谁知道我可能做错了什么?我希望显示"游戏"中的所有列以及排名表中的"排名"列.
使用Zend Framework,我创建了一个Model来将记录插入数据库.我的问题是,$this->insert($data)
如何切换活动表,以便我可以将记录插入另一个表?
到目前为止,这是我的代码:
class Model_DbTable_Foo extends Zend_Db_Table_Abstract
{
protected $_name = 'foo';
public function addFoo($params)
{
$data = array(
'foo' => $params['foo'],
);
$this->insert($data);
$foo_id = $this->getAdapter()->lastInsertId();
$data2 = array(
'bar' => $params['bar']
);
// I need to change the Db Table name here.
$this->insert($data2);
$bar_id = $this->getAdapter()->lastInsertId();
}
}
Run Code Online (Sandbox Code Playgroud) 尝试使用Zend_Db_Select
. 任何指针?
SELECT
compounds.id as compounds_id,
reactions.id as reactions_id,
reaction_compound.number as reaction_compound_number
FROM compounds, reactions, reaction_compound
WHERE
compounds.id IN (68,74,112)
AND compounds.id = reaction_compound.compound
AND reactions.id = reaction_compound.reaction;
Run Code Online (Sandbox Code Playgroud)
具体来说,我遇到的一些问题是在 Zend 中执行多个表连接。我不确定如何使用他们的查询构建器跨多个表进行连接。
任何帮助表示赞赏!
J