|
| 1 | +<?php |
| 2 | + include('griddb_php_client.php'); |
| 3 | + $data = ""; |
| 4 | +if (isset($_POST["address"]) && isset($_POST["port"]) && isset($_POST["cluster"]) && |
| 5 | + isset($_POST["user"]) && isset($_POST["password"])) { |
| 6 | + $address = $_POST["address"]; |
| 7 | + $port = $_POST["port"]; |
| 8 | + $cluster = $_POST["cluster"]; |
| 9 | + $user = $_POST["user"]; |
| 10 | + $password = $_POST["password"]; |
| 11 | + |
| 12 | + $factory = StoreFactory::get_default(); |
| 13 | + |
| 14 | + $update = true; |
| 15 | + |
| 16 | + try{ |
| 17 | + //Get GridStore object |
| 18 | + $gridstore = $factory->get_store(array("notificationAddress" => $address, |
| 19 | + "notificationPort" => $port, |
| 20 | + "clusterName" => $cluster, |
| 21 | + "user" => $user, |
| 22 | + "password" => $password |
| 23 | + )); |
| 24 | + |
| 25 | + //Create Collection |
| 26 | + $col = $gridstore->put_container("col01", array(array("name" => GS_TYPE_STRING), |
| 27 | + array("status" => GS_TYPE_BOOL), |
| 28 | + array("count" => GS_TYPE_LONG), |
| 29 | + array("lob" => GS_TYPE_BLOB)), |
| 30 | + GS_CONTAINER_COLLECTION); |
| 31 | + |
| 32 | + //Change auto commit mode to false |
| 33 | + $col->set_auto_commit(false); |
| 34 | + |
| 35 | + //Set an index on the Row-key Column |
| 36 | + $col->create_index("name", GS_INDEX_FLAG_DEFAULT); |
| 37 | + |
| 38 | + //Set an index on the Column |
| 39 | + $col->create_index("count", GS_INDEX_FLAG_DEFAULT); |
| 40 | + |
| 41 | + //Create and set row data |
| 42 | + $row = $col->create_row(); //Create row for refer |
| 43 | + $row->set_field_by_string(0, "name01"); |
| 44 | + $row->set_field_by_bool(1, False); |
| 45 | + $row->set_field_by_long(2, 1); |
| 46 | + $row->set_field_by_blob(3, "ABCDEFGHIJ"); |
| 47 | + |
| 48 | + //Put row: RowKey is "name01" |
| 49 | + $col->put_row($row); |
| 50 | + $col->commit(); |
| 51 | + $row2 = $col->create_row(); //Create row for refer |
| 52 | + $col->get_row_by_string("name01", True, $row2); //Get row with RowKey "name01" |
| 53 | + $col->delete_row_by_string("name01"); //Remove row with RowKey "name01" |
| 54 | + |
| 55 | + //Put row: RowKey is "name02" |
| 56 | + $col->put_row_by_string("name02", $row); |
| 57 | + $col->commit(); |
| 58 | + |
| 59 | + //Create normal query |
| 60 | + $query = $col->query("select * where name = 'name02'"); |
| 61 | + |
| 62 | + //Execute query |
| 63 | + $rrow = $col->create_row(); |
| 64 | + $rs = $query->fetch($update); |
| 65 | + while ($rs->has_next()){ |
| 66 | + $rs->get_next($rrow); |
| 67 | + |
| 68 | + $name = $rrow->get_field_as_string(0); |
| 69 | + $status = $rrow->get_field_as_bool(1); |
| 70 | + $count = $rrow->get_field_as_long(2) + 1; |
| 71 | + $lob = $rrow->get_field_as_blob(3); |
| 72 | + $data .= "Person: name=" . $name . " status=" . ($status ? 'true' : 'false') . " count=" . $count . " lob=" . $lob . "\n"; |
| 73 | + |
| 74 | + //Update row |
| 75 | + $rrow->set_field_by_long(2, $count); |
| 76 | + $rs->update_current($rrow); |
| 77 | + } |
| 78 | + //End transaction |
| 79 | + $col->commit(); |
| 80 | + } catch(GSException $e){ |
| 81 | + $data = $e->what(). "\n" . $e->get_code() . "\n"; |
| 82 | + } |
| 83 | +} |
| 84 | +?> |
| 85 | + |
| 86 | +<html> |
| 87 | + <body> |
| 88 | + |
| 89 | + <form action = "<?php $_PHP_SELF ?>" method = "POST"> |
| 90 | + address: <input type = "text" size="10" name = "address" /> <br><br> |
| 91 | + port: <input type = "text" size="10" name = "port" /> <br><br> |
| 92 | + cluster: <input type = "text" size="10" name = "cluster" /> <br><br> |
| 93 | + user: <input type = "text" size="10" name = "user" /> <br><br> |
| 94 | + password: <input type = "password" size="10" name = "password" /> <br><br> |
| 95 | + <br> |
| 96 | + <input type = "submit" value="submit" style="height:30px; width:90px" /> |
| 97 | + </form> |
| 98 | + |
| 99 | + <p> <?php echo $data ?> </p> |
| 100 | + |
| 101 | + </body> |
| 102 | +</html> |
0 commit comments