forked from ralphschindler/Zend_Db-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-19.php
27 lines (19 loc) · 817 Bytes
/
example-19.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
/** @var $adapter Zend\Db\Adapter\Adapter */
$adapter = include ((file_exists('bootstrap.php')) ? 'bootstrap.php' : 'bootstrap.dist.php');
refresh_data($adapter);
use Zend\Db\Sql;
use Zend\Db\ResultSet\ResultSet;
$sql = new Sql\Sql($adapter);
$subselect = $sql->select();
$subselect->from('artist')
->columns(array()) // no columns from main table
->join('album', 'artist.id = album.artist_id', array('title', 'release_date'))
//->order(array('release_date', 'title'))
->where->like('artist.name', '%Brit%');
$select = $sql->select();
$select->from(array('t' => $subselect))->columns(array('c' => new Sql\Expression('COUNT(1)')));
$statement = $sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
$row = $result->current();
assert_example_works($row['c'] == 7);