sag
A simple but powerful PHP library for talking to CouchDB.
Sag PHP & JS CouchDB Library
I have a document with an image attachment myimg.jpg
which I would like to GET using Sag.
In my browser I am able to retrieve this image if I visit this url: http://localhost:5984/mydb/thedocid/myimg.jpg
.
Using sag I am able to retrieve documents, but unable to retrieve attachments. I have tried to retrieve the image like so:
$img = $sag->get('thedocid/myimg.jpg')->body;
Instead of retrieving the image PHP seems to become unresponsive. I also thought disabling JSON decode might solve it, but it still causes PHP to become unresponsive.
$sag->decode(false);
$img = $sag->get('thedocid/myimg.jpg');
What am I doing wrong? How does one properly retrieve an attachment using Sag?
EDIT: After quite some time the attachment has been retrieved. Why is it so slow? The attachment is merely 4kb.
Source: (StackOverflow)
I'm working in getting a connection to cloudant done.
The following is using sag library for php:
<?php
header('Content-Type: text/html; charset=utf-8');
require_once('../../src/Sag.php');
//this credentials are from API key
$uName="";
$pName="";
$sag = new Sag('user.cloudant.com');
$sag->login($uName, $pName);
$sag->setDatabase('test');
try {
$result = $sag->get('/test/_design/wordsP/_view/errores');
echo ($result);
}
catch(Exception $e) {
error_log("Something's wrong");
var_dump($e);
}
?>
However I'm not getting expected result (). The view does work, if used just in the url bar.
The response is:
object(SagException)#3(6){
[
"message:protected"
]=>string(50)"Sag Error: cURL error #7: couldn't connect to host"[
"string:private"
]=>string(0)""[
"code:protected"
]=>int(0)[
"file:protected"
]=>string(73)"/home2/.../public_html/clant/src/httpAdapters/SagCURLHTTPAdapter.php"[
"line:protected"
]=>int(134)[
"trace:private"
]=>array(3){ .............
Is there something I'm not using corretly in the php script? (removed current password + username as well as account, but they're there).
Source: (StackOverflow)