Create a gist now

Instantly share code, notes, and snippets.

ZF2 JOIN方法を指定
<?php
$sm = $this->getServiceLocator();
$adapter = $sm->get('Zend\Db\Adapter\Adapter');
$sql = new \Zend\Db\Sql\Sql($adapter);
$select = $sql->select();
$select->from('album');
$select->join(
'track',
'album.id = track.album_id',
array(
'trackTitle' => 'title',
'duration'
),
'LEFT'
);
//echo $select->getSqlString($adapter->getPlatform());
$statement = $sql->prepareStatementForSqlObject($select);
$resultSet = $statement->execute();
//SELECT `album`.*, `track`.`title` AS `trackTitle`, `track`.`duration` AS `duration` FROM `album` LEFT JOIN `track` ON `album`.`id` = `track`.`album_id`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment