forked from tomwalder/php-gds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.php
42 lines (36 loc) · 1.2 KB
/
create.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
<?php
/**
* Create a single record in GDS
*
* @author Tom Walder <[email protected]>
*/
require_once('boilerplate.php');
// So now create a simple Model object
$obj_book = new GDS\Entity();
$obj_book->title = 'Romeo and Juliet';
$obj_book->author = 'William Shakespeare';
$obj_book->isbn = '1840224339';
// Insert 1 into the Datastore
$obj_book_store->upsert($obj_book);
echo "Created: ", $obj_book->getKeyId(), PHP_EOL;
// So now create a simple Model object (2)
$obj_book2 = new Book();
$obj_book2->title = "A Midsummer Night's Dream";
$obj_book2->author = 'William Shakespeare';
$obj_book2->isbn = '1853260304';
// So now create a simple Model object (3)
$obj_book3 = new Book();
$obj_book3->title = 'Hamlet';
$obj_book3->author = 'William Shakespeare';
$obj_book3->isbn = '1853260096';
$obj_book_store->upsert([$obj_book2, $obj_book3]);
echo "Created: ", $obj_book2->getKeyId(), PHP_EOL;
echo "Created: ", $obj_book3->getKeyId(), PHP_EOL;
// Create using our factory method
$obj_book4 = $obj_book_store->createEntity([
'title' => 'The Merchant of Venice',
'author' => 'William Shakespeare',
'isbn' => '1840224312'
]);
$obj_book_store->upsert($obj_book4);
echo "Created: ", $obj_book4->getKeyId(), PHP_EOL;