Php 具有多个表联接的Zend DB Select
尝试使用Php 具有多个表联接的Zend DB Select,php,sql,zend-framework,Php,Sql,Zend Framework,尝试使用Zend\u Db\u 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)
Zend\u Db\u 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;
具体来说,我遇到的一些问题是在Zend中进行多表联接。我不知道如何使用查询生成器跨多个表进行连接
感谢您的帮助
J类似的东西:
$compoundIds = array(68,74,112);
$select = $db->select()
->from('compounds', array('compounds_id' => 'id')
->where('compounds.id in ( ? )', $compoundIds)
->join('reaction_compound', 'compounds.id = reaction_compound.compound', array('reaction_compound_number' => 'number'))
->join('reactions', 'reactions.id = reaction_compound.reaction', array('reaction_id' => 'id');
这应该会让你有所收获。我没有测试它,因此其中可能有一些错误。格式:
$db->select()->from('table_name')->join('...')->join('...')
很好谢谢你们两位的海报提供这些信息!帮我解决了一个难题!(抽象表格模型哦,天哪!!)哈哈 Ps:对于将要使用上述相同格式的其他人,请记住列名将被具有相同列名的后面的表覆盖。 快乐编码