couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Bisbee <...@sbisbee.com>
Subject Re: SIMPLE PHP EXAMPLE
Date Wed, 04 Aug 2010 19:39:39 GMT
Hi Paul,

I use PHP and CouchDB together nearly every day, so here are some quick
thoughts. 

I would also recommend that you take a look at Sag (www.saggingcouch.com or
github.com/ravidgemole/sag), the PHP library I wrote for CouchDB; not that I'm
biased or anything.

On Mon, Aug 02, 2010 at 12:00:08PM -0700, Paul J Barrett wrote:
> I see many examples of using some library api to use php with couchdb, but I
> don't see anything that demonstrates using json and making the put, post,
> get, delete directly using the REST interface.

In PHP we do 99% of our JSON work with json_encode() and json_decode(). Some
PHP implementations hide this from their users, but they're really just using
those two functions behind the OOP curtain.

> Is it that difficult to use php directly with couchdb that you need the added
> frameworks? 

Nope, it just makes it easier so that you don't have to worry about configuring
cURL, formatting packets, or dealing with streams/sockets. This is a language
agnostic consideration. Ex., you wouldn't want to implement AJAX yourself for
JavaScript - you would use a library like jQuery.

Side note, I'm not sure if, or where, you're drawing the line between framework
and library.

> I only work with php infrequently so I am no master php developer
> but it seems a little overly complicated considering that most Couchdb
> tutorials demonstrate the basics using curl. 

If you like cURL, then I'd recommend looking at PHP's library www.php.net/curl.
If you're on a Debian based Linux distro, then `sudo apt-get install php5-curl`
will do the trick.

Also, the reason so many tutorials use cURL for demonstration is that it's
language agnostic: you don't need to know the author's language of choice to
understand the tutorial. And using an actual program is better than just
showing HTTP packets, because the reader might not know enough about the
protocol and they can simply re-run the examples (can't really "re-run" a
packet).

> The websites I develop usually have some simple forms (guest book, or
> something similar) and simple retrieval mechanisms so I am looking for the
> simplest way to start using couchdb.

Again, take a look at Sag - I try to build it with relaxation and simplicity.
And yes, there are other libraries that you can try too.

Cheers,

-- 
Sam Bisbee
www.sbisbee.com

Mime
View raw message