Skip to content
Visit booth 3171 at Google Cloud Next to see how to unlock real-time decisions at scaleMore info

Create

The following example code creates a new record in an Aerospike database.

<?php
namespace Aerospike;
// Create a new connection
try{
$socket = "/tmp/asld_grpc.sock";
$client = Client::connect($socket);
var_dump($client->hosts);
}catch(AerospikeException $e){
var_dump($e);
}
// Define a key with a namespace, set name, and user-defined key
$key = new Key("namespace", "set_name", 1);
$wp = new WritePolicy();
// Define several bins with different data types
$bin1 = new Bin("bin1", 111);
$bin2 = new Bin("bin2", "string");
$bin3 = new Bin("bin3", 333.333);
$bin4 = new Bin("bin4", [
"str",
1984,
333.333,
[1, "string", 5.1],
[
"integer" => 1984,
"float" => 333.333,
"list" => [1, "string", 5.1]
]
]);
$bin5 = new Bin("bin5", [
"integer" => 1984,
"float" => 333.333,
"list" => [1, "string", 5.1],
null => [
"integer" => 1984,
"float" => 333.333,
"list" => [1, "string", 5.1]
],
"" => [ 1, 2, 3 ],
]);
// Use put to create the new record
$client->put($wp, $key, [$bin1, $bin2, $bin3, $bin4, $bin5]);
// Close the connection
$client->close()
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?