本文介绍了ZEND FW:连接来自不同数据库的两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在同一服务器上的differenet数据库中联接两个表.有人可以告诉我如何在Zend Frameworks Db适配器中做到这一点吗?
I want to join two tables in differenet databases on the same server.Could someone tell me how I could do this in Zend Frameworks Db adapter?
推荐答案
在连接来自不同数据库的两个表之前,先从dbAdapter构建tableGateway.
Build tableGateway from your dbAdapter before joining two tables from different database.
use use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
$someCondition=new Where();
$someCondition->equalTo('columnName',$columnValue);
//you can build $this->tableGateway from your DB adapter
$rowset = $this->tableGateway->select(function (Select $select) use ($someCondition) {
$table2forInnerJoin = new \Zend\Db\Sql\TableIdentifier('table2Name', 'table2Database');
$select->join(array('table2Name'=>$table2forInnerJoin),"table1Name.id = table2Name.id");
$select->where($someCondition);
});
return $rowset;
这篇关于ZEND FW:连接来自不同数据库的两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!