-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.php
66 lines (49 loc) · 1.76 KB
/
test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require 'vendor/autoload.php';
$apiKey = "YOUR-API-KEY";
$db = "test";
$flybase = new \Flybase\Client( $apiKey,$db );
$users = $flybase->Users; // where Tasks is your collection
$lead = array();
$lead['Name'] = 'Test User';
$lead['PhoneNumber'] = '123-456-1234';
$lead['DateCreated'] = date('Y-m-d H:i:s');
// Ok, how about inserting a new record:
$inserted_id = $users->insert( $lead );
// Now, let’s get all records:
echo '<h4>Get All</h4>';
$ret = $users->get();
echo '<pre>'.print_r($ret,true).'</pre>';
// We can also get a record based on a single id:
echo '<hr />';
echo '<h4>Get By _id</h4>';
$ret = $users->get('544d8df66865edoc371206478');
echo '<pre>'.print_r($ret,true).'</pre>';
// Or, you can query based on other fields:
echo '<hr />';
echo '<h4>Get By "PhoneNumber"</h4>';
$ret = $users->find( array('PhoneNumber'=>'6486490392721') );
echo '<pre>'.print_r($ret,true).'</pre>';
// Now, let’s update a record:
echo '<hr />';
echo '<h4>Update By "PhoneNumber"</h4>';
$ret = $users->find( array('PhoneNumber'=>'6486490392721') );
echo '<pre>'.print_r($ret,true).'</pre>';
$row = $ret[0];
$row['Role'] = 'Nobody';
$ret = $users->updatebyid($row,$row['_id']);
$ret = $users->find( array('PhoneNumber'=>'6486490392721') );
echo '<pre>'.print_r($ret,true).'</pre>';
// Or, you can update this way:
echo '<hr />';
echo '<h4>Alternate Update</h4>';
$ret = $users->find( array("Name"=>"Lorenza Huels") );
echo '<pre>'.print_r($ret,true).'</pre>';
$row = array(
"Role"=>"Teacher",
);
$ret = $users->update(array("Name"=>"Lorenza Huels"),$row);
$ret = $users->find( array("Name"=>"Lorenza Huels") );
echo '<pre>'.print_r($ret,true).'</pre>';
// And finally, let’s delete the record:
# $users->delete('544d8df63cffddoc853542530');