Eric Mitjans
Eric Mitjans

Reputation: 2169

Getting all docs from Cloudant with PHP and CURL

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?

Upvotes: 0

Views: 201

Answers (1)

Lorna Mitchell
Lorna Mitchell

Reputation: 1986

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?

Upvotes: 1

Related Questions