ZF2如何用连接重命名字段名称

dir*_*ory 5 mysql join zend-framework2

因为我的连接包括一个名为"id"的字段,所以我需要在我的sql期间重命名这个字段名,这样它就不会覆盖我从第一个选中的tabel中的id字段名.

我的查询看起来如下;

$select = new \Zend\Db\Sql\Select();
$select->from('websites');
$select->join(array('s' => 'websites_statistics'), 's.website_id = websites.id');
$select->where(array('websites.website' => $website));
$select->order('s.timestamp DESC')->limit(1);

$rowset = $this->tableGateway->selectWith($select);
$row = $rowset->current();

return $row;
Run Code Online (Sandbox Code Playgroud)

因此,'s''id'字段应该重命名为'stat_id'.

提前致谢!

缺口

Dav*_*aub 10

$select = new \Zend\Db\Sql\Select();
$select->from('websites');
       ->join(array('s' => 'websites_statistics'), 's.website_id = websites.id',
           array('stat_id' => 's.id')); // <-- here is the alias
       ->where(array('websites.website' => $website));
       ->order('s.timestamp DESC')
       ->limit(1);
Run Code Online (Sandbox Code Playgroud)