Skip to content

Commit 54ca075

Browse files
committed
add new samples for 0.8
1 parent 43b5fce commit 54ca075

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

sample/ContainerInformation.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
include('griddb_php_client.php');
3+
4+
$factory = StoreFactory::getInstance();
5+
6+
$containerName = "SamplePHP_Info";
7+
8+
try {
9+
// Get GridStore object
10+
$gridstore = $factory->getStore(["host" => $argv[1],
11+
"port" => (int)$argv[2],
12+
"clusterName" => $argv[3],
13+
"username" => $argv[4],
14+
"password" => $argv[5]]);
15+
16+
// Create a collection container
17+
$conInfo = new ContainerInfo(["name" => $containerName,
18+
"columnInfoArray" => [["id", Type::INTEGER],
19+
["productName", Type::STRING],
20+
["count", Type::INTEGER]],
21+
"type" => ContainerType::COLLECTION,
22+
"rowKey" => true]);
23+
24+
$col = $gridstore->putContainer($conInfo);
25+
echo("Sample data generation: Create Collection name=$containerName\n");
26+
27+
// Get container information
28+
// (1)Get container information
29+
$containerInfo = $gridstore->getContainerInfo($containerName);
30+
31+
// (2)Display container information
32+
echo("Get containerInfo:\n name =".$containerInfo->name."\n");
33+
34+
if ($containerInfo->type == ContainerType::COLLECTION) {
35+
echo(" type=Collection\n");
36+
} else {
37+
echo(" type=Timeseries\n");
38+
}
39+
40+
echo(" rowKeyAssigned=". (($containerInfo->rowKey) ? "true" : "false")."\n");
41+
42+
$count = sizeof($containerInfo->columnInfoArray);
43+
echo(" columnCount=$count\n");
44+
45+
for ($i = 0; $i < $count; $i++) {
46+
echo(" column (".$containerInfo->columnInfoArray[$i][0].", ".$containerInfo->columnInfoArray[$i][1].")\n");
47+
}
48+
echo("success!\n");
49+
} catch (GSException $e) {
50+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
51+
echo("\n[$i]\n");
52+
echo($e->getErrorCode($i)."\n");
53+
echo($e->getLocation($i)."\n");
54+
echo($e->getErrorMessage($i)."\n");
55+
}
56+
}
57+
?>

sample/PutRows.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::getInstance();
5+
6+
$containerName = "SamplePHP_PutRows";
7+
$rowCount = 5;
8+
$rowArray = [];
9+
10+
try {
11+
// Get GridStore object
12+
$gridstore = $factory->getStore(["host" => $argv[1],
13+
"port" => (int)$argv[2],
14+
"clusterName" => $argv[3],
15+
"username" => $argv[4],
16+
"password" => $argv[5]]);
17+
18+
// Create a collection
19+
$conInfo = new ContainerInfo(["name" => $containerName,
20+
"columnInfoArray" => [["id", Type::INTEGER],
21+
["productName", Type::STRING],
22+
["count", Type::INTEGER]],
23+
"type" => ContainerType::COLLECTION,
24+
"rowKey" => true]);
25+
26+
$col = $gridstore->putContainer($conInfo);
27+
echo("Create Collection name=$containerName\n");
28+
29+
// Register multiple rows
30+
// (1)Get the container
31+
$col1 = $gridstore->getContainer($containerName);
32+
if ($col1 == null) {
33+
echo("ERROR Container not found. name=$containerName\n");
34+
}
35+
36+
// Register multiple rows
37+
for ($i = 0; $i < $rowCount; $i++) {
38+
$row = [];
39+
array_push($row, $i, "dvd", 10*$i);
40+
array_push($rowArray, $row);
41+
$col1->multiPut($rowArray);
42+
}
43+
44+
echo("Put rows\n");
45+
echo("success!\n");
46+
} catch (GSException $e) {
47+
for ($i= 0; $i < $e->getErrorStackSize(); $i++) {
48+
echo("\n[$i]\n");
49+
echo($e->getErrorCode($i)."\n");
50+
echo($e->getLocation($i)."\n");
51+
echo($e->getErrorMessage($i)."\n");
52+
}
53+
}
54+
?>

0 commit comments

Comments
 (0)