(PECL tokyo_tyrant >= 0.1.0)
TokyoTyrantTable::putKeep — Put a new record
Puts a new record into the database. If the key already exists this method throws an exception indicating that the records exists.
The primary key of the row or NULL
Array of the row contents
Returns the primary key and throws TokyoTyrantException on error.
Пример #1 TokyoTyrantTable::putKeep() example
<?php
/* Connect to a table database */
$tt = new TokyoTyrantTable("localhost", 1979);
/* Passing null to put generates a new uid */
$index = $tt->put(null, array("column1" => "some data", "column2" => "more data"));
/* Get the row back */
var_dump($tt->get($index));
try {
$tt->putKeep($index, array("column1" => "something new", "new_column" => "other data"));
} catch (TokyoTyrantException $e) {
if ($e->getCode() === TokyoTyrant::TTE_KEEP) {
echo "Existing record! Not modified\n";
} else {
echo "Error: " , $e->getMessage() , "\n";
}
}
/* Get the row back */
var_dump($tt->get($index));
?>
Результатом выполнения данного примера будет что-то подобное:
array(2) { ["column1"]=> string(9) "some data" ["column2"]=> string(9) "more data" } Existing record! Not modified array(2) { ["column1"]=> string(9) "some data" ["column2"]=> string(9) "more data" }