|
1 | 1 | <?php |
2 | 2 | include('griddb_php_client.php'); |
3 | 3 |
|
4 | | - $factory = StoreFactory::get_default(); |
| 4 | + $factory = StoreFactory::getInstance(); |
5 | 5 |
|
6 | 6 | $containerName = "SamplePHP_BlobData"; |
7 | 7 |
|
8 | 8 | try { |
9 | 9 | // Get GridStore object |
10 | | - $gridstore = $factory->get_store(array("notificationAddress" => $argv[1], |
11 | | - "notificationPort" => $argv[2], |
| 10 | + $gridstore = $factory->getStore(["host" => $argv[1], |
| 11 | + "port" => (int)$argv[2], |
12 | 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"); |
| 13 | + "username" => $argv[4], |
| 14 | + "password" => $argv[5]]); |
20 | 15 |
|
21 | 16 | // 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 | | - ); |
| 17 | + $conInfo = new ContainerInfo(["name" => $containerName, |
| 18 | + "columnInfoArray" => [["id", Type::INTEGER], |
| 19 | + ["blob", Type::BLOB]], |
| 20 | + "type" => ContainerType::COLLECTION, |
| 21 | + "rowKey" => true]); |
| 22 | + |
| 23 | + $col = $gridstore->putContainer($conInfo); |
28 | 24 | echo("Create Collection name=$containerName\n"); |
29 | 25 |
|
30 | 26 | // 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); |
| 27 | + // (1)Get contents of a file into a string |
| 28 | + $filename = "sample/BlobData.php"; |
| 29 | + $handle = fopen($filename, "rb"); |
| 30 | + $blobString = fread($handle, filesize($filename)); |
| 31 | + fclose($handle); |
| 32 | + |
| 33 | + //(2)Register a row |
| 34 | + $col->put([0, $blobString]); |
41 | 35 | echo("Put Row (Blob)\n"); |
42 | 36 |
|
43 | 37 | // 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"); |
| 38 | + $row = $col->get(0); |
| 39 | + echo("Get Row (Blob content: \n$row[1]\nBlob size = ".strlen($row[1]).")\n"); |
51 | 40 | echo("success!\n"); |
52 | 41 | } catch (GSException $e) { |
53 | | - echo($e->what()."\n"); |
54 | | - echo($e->get_code()."\n"); |
| 42 | + for ($i= 0; $i < $e->getErrorStackSize(); $i++) { |
| 43 | + echo("\n[$i]\n"); |
| 44 | + echo($e->getErrorCode($i)."\n"); |
| 45 | + echo($e->getLocation($i)."\n"); |
| 46 | + echo($e->getErrorMessage($i)."\n"); |
| 47 | + } |
55 | 48 | } |
56 | 49 | ?> |
0 commit comments