Quantcast
Channel: 一言多いプログラマーの独り言
Viewing all articles
Browse latest Browse all 846

PHPでApache CouchDBにアクセスして、UUIDを取得

$
0
0
PHPでApache CouchDBにアクセスして、UUIDを取得です。 アクセスURLの末尾に「_uuids」を指定すればOK。「/_uuids?count=10」という具合にすると、一度に10個取得できます。


<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://admin:password@127.0.0.1:5984/_uuids');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Accept: */*'
));

$response = curl_exec($ch);
$_response = json_decode($response, true);

$UUID = $_response['uuids'];
curl_close($ch);

header('content-type: application/json; charset=utf-8');
echo $response ;
?>

{
"uuids": [
"58c65c9e0b312f7c034933d0ec007bd2"
]
}

参考サイト
CouchDB for PHP developers - CRUD(Inchooさん)
UUID がぶつかる可能性を考えなくていい理由(Qiita)

Viewing all articles
Browse latest Browse all 846

Latest Images

Trending Articles