Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 具有多个表联接的Zend DB Select_Php_Sql_Zend Framework - Fatal编程技术网

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:对于将要使用上述相同格式的其他人,请记住列名将被具有相同列名的后面的表覆盖。 快乐编码