-
Notifications
You must be signed in to change notification settings - Fork 24
/
example-16.php
48 lines (39 loc) · 1.44 KB
/
example-16.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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\Sql,
Zend\Db\ResultSet\ResultSet;
$sql = new Sql($adapter);
$select = $sql->select();
$select->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'))
->limit(2)->offset(0)
->where->like('artist.name', '%Brit%');
// prepare statement in a platform specific way
$statement = $sql->prepareStatementForSqlObject($select);
$container = $statement->getParameterContainer();
// create iterable result set
$resultSet = new ResultSet();
// as we iterate bind the new offset to the existing statement
foreach (array(0, 2, 4) as $offset) {
$container->offsetSet('offset', $offset);
$resultSet->initialize($statement->execute());
$output = '';
foreach ($resultSet->toArray() as $row) {
$output .= '|' . $row['title'] . '|';
}
switch ($offset) {
case 0:
assert_example_works($output === '|...Baby One More Time||Oops!... I Did It Again|', true);
break;
case 2:
assert_example_works($output === '|Britney||Blackout|', true);
break;
case 4:
assert_example_works($output === '|Circus||Femme Fatale|');
break;
}
}