forked from ralphschindler/Zend_Db-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-07.php
26 lines (19 loc) · 819 Bytes
/
example-07.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
<?php
$adapter = include ((file_exists('bootstrap.php')) ? 'bootstrap.php' : 'bootstrap.dist.php');
refresh_data($adapter);
/* @var $adapter Zend\Db\Adapter */
$artistTable = new Zend\Db\TableGateway\TableGateway('artist', $adapter);
$result = $artistTable->insert(array(
'name' => 'New Artist',
'history' => 'This is the history'
));
$id = $artistTable->getLastInsertValue();
if ($id == null && $adapter->getPlatform()->getName() == 'PostgreSQL') {
$id = $adapter->getDriver()->getConnection()->getLastGeneratedValue('artist_id_seq');
}
assert_example_works($result === 1, true);
$artistTable = new Zend\Db\TableGateway\TableGateway('artist', $adapter);
$rowset = $artistTable->select(array('id' => $id));
$row = $rowset->current();
$name = $row['name'];
assert_example_works($name == 'New Artist');