©
本文档使用 PHP中文网手册 发布
(PECL tokyo_tyrant >= 0.1.0)
TokyoTyrantTable::putKeep — Put a new record
$key
, array $columns
)Puts a new record into the database. If the key already exists this method throws an exception indicating that the records exists.
key
The primary key of the row or NULL
columns
Array of the row contents
Returns the primary key and throws TokyoTyrantException on error.
Example #1 TokyoTyrantTable::putKeep() example
<?php
$tt = new TokyoTyrantTable ( "localhost" , 1979 );
$index = $tt -> put ( null , array( "column1" => "some data" , "column2" => "more data" ));
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" ;
}
}
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" }