-
Notifications
You must be signed in to change notification settings - Fork 24
/
example-02.php
executable file
·44 lines (31 loc) · 1.26 KB
/
example-02.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
<?php
/**
* Issue INSERT command through adapter using array paramaterization (default)
*/
/* @var Zend\Db\Adapter\Adapter $adapter */
$adapter = include ((file_exists('bootstrap.php')) ? 'bootstrap.php' : 'bootstrap.dist.php');
refresh_data($adapter);
$qi = function($name) use ($adapter) { return $adapter->platform->quoteIdentifier($name); };
$fp = function($name) use ($adapter) { return $adapter->driver->formatParameterName($name); };
$sql = 'INSERT INTO '
. $qi('artist')
. ' (' . $qi('name') . ', ' . $qi('history') . ') VALUES ('
. $fp('name') . ', ' . $fp('history') . ')';
/* @var $statement Zend\Db\Adapter\Driver\StatementInterface */
$statement = $adapter->query($sql);
$parameters = array(
'name' => 'New Artist',
'history' => 'This is the history'
);
$result = $statement->execute($parameters);
$id = (int) $result->getGeneratedValue();
// DATA INSERTED, NOW CHECK
/* @var $statement Zend\Db\Adapter\Driver\StatementInterface */
$statement = $adapter->query('SELECT * FROM '
. $qi('artist')
. ' WHERE ' . $qi('id') . ' = ' . $fp('id'));
/* @var $results Zend\Db\ResultSet\ResultSet */
$results = $statement->execute(array('id' => $id));
$row = $results->current();
$name = $row['name'];
assert_example_works($name == 'New Artist');