0

I'm trying to fetch all the docs from my CouchDB hosted in Cloudant, using PHP and CURL.

So far I've tried this, I get a 200 status, but nothing on the Response column of the console.

<?php

$url = "https://myuser.cloudant.com/mydb/_all_docs?include_docs=true";
$user = 'myuser';
$pass = 'mypass';
$ch = curl_init();   // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);

$info = curl_getinfo($ch);
return $output;
return json_decode($output,true);   
curl_close($ch);

?>

I'm not fluent in PHP, what am I missing?

1 Answer 1

1

A couple of things look odd to me about the above code sample. I usually put the credentials in the URL so https://user:[email protected] as the URL - then you don't need the following two curl_setopt lines. I'm not exactly sure how it would work to pass those separately.

Also you're returning twice. If you just want to inspect the output try the var_dump() command and see if that shows you what you expect?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.