|
| 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 | +?> |
0 commit comments