Skip to content

Instantly share code, notes, and snippets.

@chardcastle
Created February 20, 2014 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chardcastle/9110721 to your computer and use it in GitHub Desktop.
Save chardcastle/9110721 to your computer and use it in GitHub Desktop.
Stash data away into couchdb (build script)
<?php
// Get a unique ID for document
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://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: */*'
));
// No security at present
// curl_setopt($ch, CURLOPT_USERPWD, 'myDBusername:myDBpass');
$response = curl_exec($ch);
$_response = json_decode($response, true);
$UUID = array_shift($_response['uuids']);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://127.0.0.1:5984/{$databaseName}/{$UUID}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); /* or PUT */
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Accept: */*'
));
// curl_setopt($ch, CURLOPT_USERPWD, 'myDBusername:myDBpass');
$response = curl_exec($ch);
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment