Skip to content

Commit d8b4ee1

Browse files
committed
add sample codes for main features
1 parent db8b5de commit d8b4ee1

15 files changed

+950
-0
lines changed

sample/BlobData.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
$containerName = "SamplePHP_BlobData";
7+
8+
try {
9+
// Get GridStore object
10+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11+
"notificationPort" => $argv[2],
12+
"clusterName" => $argv[3],
13+
"user" => $argv[4],
14+
"password" => $argv[5]
15+
));
16+
17+
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18+
$gridstore->get_container("containerName");
19+
echo("Connect to Cluster\n");
20+
21+
// Create a collection container
22+
$col = $gridstore->put_container(
23+
$containerName,
24+
array(array("id" => GS_TYPE_INTEGER),
25+
array("blob" => GS_TYPE_BLOB)),
26+
GS_CONTAINER_COLLECTION
27+
);
28+
echo("Create Collection name=$containerName\n");
29+
30+
// Register string data
31+
// (1)Read string data file
32+
$blobString = file_get_contents('BlobData.php');
33+
34+
// (2)Create and set row data
35+
$row = $col->create_row(); //Create row for refer
36+
$row->set_field_by_integer(0, 0);
37+
$row->set_field_by_blob(1, $blobString);
38+
39+
// (3)Put row
40+
$col->put_row($row);
41+
echo("Put Row (Blob)\n");
42+
43+
// Get string data file from row
44+
// (1)Create an empty Row object
45+
$row1 = $col->create_row();
46+
47+
// (2)Specify row key and get row
48+
$col->get_row_by_integer(0, false, $row1);
49+
$blob = $row1->get_field_as_blob(1);
50+
echo("Get Row (Blob string data=$blob");
51+
echo("success!\n");
52+
} catch (GSException $e) {
53+
echo($e->what()."\n");
54+
echo($e->get_code()."\n");
55+
}
56+
?>

sample/Connect.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
try {
7+
// (1)Get GridStore object
8+
// Multicast method
9+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
10+
"notificationPort" => $argv[2],
11+
"clusterName" => $argv[3],
12+
"user" => $argv[4],
13+
"password" => $argv[5]
14+
));
15+
16+
// Fixed list method
17+
//$gridstore = $factory->get_store(array("notificationMember" => $argv[1],
18+
// "clusterName" => $argv[2],
19+
// "user" => $argv[3],
20+
// "password" => $argv[4]
21+
// ));
22+
23+
// Provider method
24+
//$gridstore = $factory->get_store(array("notificationProvider" => $argv[1],
25+
// "clusterName" => $argv[2],
26+
// "user" => $argv[3],
27+
// "password" => $argv[4]
28+
// ));
29+
30+
// (2)When operations such as container creation and acquisition are performed, it is connected to the cluster.
31+
$gridstore->get_container("containerName");
32+
echo("Connect to Cluster\n");
33+
echo("success!\n");
34+
} catch (GSException $e) {
35+
echo($e->what()."\n");
36+
echo($e->get_code()."\n");
37+
}
38+
?>

sample/ContainerNames.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
try {
7+
// Get GridStore object
8+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
9+
"notificationPort" => $argv[2],
10+
"clusterName" => $argv[3],
11+
"user" => $argv[4],
12+
"password" => $argv[5]
13+
));
14+
15+
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
16+
$gridstore->get_container("containerName");
17+
echo("Connect to Cluster\n");
18+
19+
// Get a list of container names
20+
// (1)Get partition controller and number of partitions
21+
$pc = $gridstore->get_partition_controller();
22+
$pcCount = $pc->get_partition_count();
23+
24+
// (2)Loop by the number of partitions to get a list of container names
25+
for ($i = 0; $i < $pcCount; $i++) {
26+
$nameList = $pc->get_partition_container_names($i, 0);
27+
$nameCount = sizeof($nameList);
28+
for ($j = 0; $j < $nameCount; $j++) {
29+
echo("$nameList[$j]\n");
30+
}
31+
}
32+
} catch (GSException $e) {
33+
echo($e->what()."\n");
34+
echo($e->get_code()."\n");
35+
}
36+
?>

sample/CreateCollection.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
$containerName = "SamplePHP_collection1";
7+
8+
try {
9+
// Get GridStore object
10+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11+
"notificationPort" => $argv[2],
12+
"clusterName" => $argv[3],
13+
"user" => $argv[4],
14+
"password" => $argv[5]
15+
));
16+
17+
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18+
$gridstore->get_container("containerName");
19+
echo("Connect to Cluster\n");
20+
21+
// Create a collection container
22+
$col = $gridstore->put_container(
23+
$containerName,
24+
array(array("id" => GS_TYPE_INTEGER),
25+
array("productName" => GS_TYPE_STRING),
26+
array("count" => GS_TYPE_INTEGER)),
27+
GS_CONTAINER_COLLECTION
28+
);
29+
echo("Create Collection name=$containerName\n");
30+
echo("success!\n");
31+
} catch (GSException $e) {
32+
echo($e->what()."\n");
33+
echo($e->get_code()."\n");
34+
}
35+
?>

sample/CreateIndex.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
$containerName = "SamplePHP_Index";
7+
8+
try {
9+
// Get GridStore object
10+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11+
"notificationPort" => $argv[2],
12+
"clusterName" => $argv[3],
13+
"user" => $argv[4],
14+
"password" => $argv[5]
15+
));
16+
17+
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18+
$gridstore->get_container("containerName");
19+
echo("Connect to Cluster\n");
20+
21+
// Create a collection container
22+
$col = $gridstore->put_container(
23+
$containerName,
24+
array(array("id" => GS_TYPE_INTEGER),
25+
array("productName" => GS_TYPE_STRING),
26+
array("count" => GS_TYPE_INTEGER)),
27+
GS_CONTAINER_COLLECTION
28+
);
29+
echo("Create Collection name=$containerName\n");
30+
31+
// Get the container
32+
$container = $gridstore->get_container($containerName);
33+
if ($container == null) {
34+
echo("ERROR Container not found. name=$containerName\n");
35+
}
36+
37+
// Create an index
38+
$container->create_index("count", GS_INDEX_FLAG_HASH);
39+
echo("Create Index\n");
40+
echo("success!\n");
41+
} catch (GSException $e) {
42+
echo($e->what()."\n");
43+
echo($e->get_code()."\n");
44+
}
45+
?>

sample/CreateTimeSeries.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
$containerName = "SamplePHP_timeseries1";
7+
8+
try {
9+
// Get GridStore object
10+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11+
"notificationPort" => $argv[2],
12+
"clusterName" => $argv[3],
13+
"user" => $argv[4],
14+
"password" => $argv[5]
15+
));
16+
17+
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18+
$gridstore->get_container("containerName");
19+
echo("Connect to Cluster\n");
20+
21+
// Create a timeseries container
22+
$col = $gridstore->put_container(
23+
$containerName,
24+
array(array("date" => GS_TYPE_TIMESTAMP),
25+
array("value" => GS_TYPE_DOUBLE)),
26+
GS_CONTAINER_TIME_SERIES
27+
);
28+
echo("Create Timeseries name=$containerName\n");
29+
echo("success!\n");
30+
} catch (GSException $e) {
31+
echo($e->what()."\n");
32+
echo($e->get_code()."\n");
33+
}
34+
?>

sample/GetRow.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
$containerName = "SamplePHP_GetRow";
7+
$rowCount = 5;
8+
$nameList = array("notebook PC", "desktop PC", "keyboard", "mouse", "printer");
9+
$numberList = array(108, 72, 25, 45, 62);
10+
$rowList = array();
11+
$rowList1 = array();
12+
$id = array();
13+
$productName = array();
14+
$count = array();
15+
16+
try {
17+
// Get GridStore object
18+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
19+
"notificationPort" => $argv[2],
20+
"clusterName" => $argv[3],
21+
"user" => $argv[4],
22+
"password" => $argv[5]
23+
));
24+
25+
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
26+
$gridstore->get_container("containerName");
27+
echo("Connect to Cluster\n");
28+
29+
// Create a collection container
30+
$col = $gridstore->put_container(
31+
$containerName,
32+
array(array("id" => GS_TYPE_INTEGER),
33+
array("productName" => GS_TYPE_STRING),
34+
array("count" => GS_TYPE_INTEGER)),
35+
GS_CONTAINER_COLLECTION
36+
);
37+
echo("Sample data generation: Create Collection name=$containerName\n");
38+
39+
// Create and set row data
40+
for ($i = 0; $i < $rowCount; $i++) {
41+
// (1)Create an empty Row object
42+
$rowList[$i] = $col->create_row();
43+
44+
// (2)Set the value in the Row object
45+
$rowList[$i]->set_field_by_integer(0, $i);
46+
$rowList[$i]->set_field_by_string(1, $nameList[$i]);
47+
$rowList[$i]->set_field_by_integer(2, $numberList[$i]);
48+
$col->put_row($rowList[$i]);
49+
}
50+
echo("Sample data generation: Put Rows count=$rowCount\n");
51+
52+
// Get a row
53+
// (1)Get the container
54+
$col1 = $gridstore->get_container($containerName);
55+
if ($col1 == null) {
56+
echo("ERROR Container not found. name=$containerName\n");
57+
}
58+
59+
for ($i = 0; $i < $rowCount; $i++) {
60+
// (2)Create an empty Row object
61+
$rowList1[$i] = $col1->create_row();
62+
63+
// (3)Specify row key and get row
64+
$col1->get_row_by_integer($i, false, $rowList1[$i]);
65+
66+
//(4)Get value from Row
67+
$id[$i] = $rowList1[$i]->get_field_as_integer(0);
68+
$productName[$i] = $rowList1[$i]->get_field_as_string(1);
69+
$count[$i] = $rowList1[$i]->get_field_as_integer(2);
70+
}
71+
72+
echo("Get Row (id=$id[0], productName=$productName[0], count=$count[0])\n");
73+
echo("success!\n");
74+
} catch (GSException $e) {
75+
echo($e->what()."\n");
76+
echo($e->get_code()."\n");
77+
}
78+
?>

sample/PutRow.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::get_default();
5+
6+
$containerName = "SamplePHP_PutRow";
7+
8+
try {
9+
// Get GridStore object
10+
$gridstore = $factory->get_store(array("notificationAddress" => $argv[1],
11+
"notificationPort" => $argv[2],
12+
"clusterName" => $argv[3],
13+
"user" => $argv[4],
14+
"password" => $argv[5]
15+
));
16+
17+
// When operations such as container creation and acquisition are performed, it is connected to the cluster.
18+
$gridstore->get_container("containerName");
19+
echo("Connect to Cluster\n");
20+
21+
// Create a collection container
22+
$col = $gridstore->put_container(
23+
$containerName,
24+
array(array("id" => GS_TYPE_INTEGER),
25+
array("productName" => GS_TYPE_STRING),
26+
array("count" => GS_TYPE_INTEGER)),
27+
GS_CONTAINER_COLLECTION
28+
);
29+
echo("Create Collection name=$containerName\n");
30+
31+
// Register a row
32+
// (1)Get the container
33+
$col1 = $gridstore->get_container($containerName);
34+
if ($col1 == null) {
35+
echo("ERROR Container not found. name=$containerName\n");
36+
}
37+
38+
// (2)Create an empty Row object
39+
$row = $col1->create_row();
40+
41+
// (3)Set column value
42+
$row->set_field_by_integer(0, 0);
43+
$row->set_field_by_string(1, "display");
44+
$row->set_field_by_integer(2, 150);
45+
46+
// (4)Register the row
47+
$col1->put_row($row);
48+
echo("Put Row\n");
49+
echo("success!\n");
50+
} catch (GSException $e) {
51+
echo($e->what()."\n");
52+
echo($e->get_code()."\n");
53+
}
54+
?>

0 commit comments

Comments
 (0)