forked from Vizzuality/cartodbclient-php
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.php
59 lines (45 loc) · 1.63 KB
/
example.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
<?php
require_once 'cartodb.class.php';
require_once 'cartodb.config.php';
$config = getConfig();
$cartodb = new CartoDBClient($config);
#Check if the $key and $secret work fine and you are authorized
if (!$cartodb->authorized) {
error_log("uauth");
print 'There is a problem authenticating, check the key and secret.';
exit();
}
#Now we can perform queries straigh away. The second param indicates if you want
#the result to be json_decode (true) or just return the raw json string
// $schema = array(
// 'col1' => 'text',
// 'col2' => 'integer'
// );
// $response = $cartodb->createTable('example', $schema);
// var_dump($response);
// $response = $cartodb->addColumn('example', 'col3', 'text');
// var_dump($response);
// $response = $cartodb->dropColumn('example', 'col2');
// var_dump($response);
$data = array(
'name' => "'row1 - col1'",
'description' => "'row1 - col3'",
);
$response = $cartodb->insertRow('example', $data);
$row = array_pop($response['return']['rows']);
var_dump($row);
// $data['col1'] = "'row1 - col1 new'";
// $data['col3'] = "'row1 - col3 new'";
// $response = $cartodb->updateRow('example', $row->id, $data);
// var_dump($response);
// $response = $cartodb->getRow('example', $row->id);
// $var_dump($response);
// $response = $cartodb->deleteRow('example', $row->id);
// var_dump($response);
// $response = $cartodb->getRecords('example', array('rows_per_page' => 0));
// $total_rows = $response['return']['total_rows'];
// $response = $cartodb->getRecords('example', array('rows_per_page' => $total_rows));
// var_dump($response);
// $response = $cartodb->dropTable('example');
// var_dump($response);
?>