USING COUCHDB WITH PHP

2012-02-25

Introduction

Since couchdb provides a REST interface, it is tempting use AJAX
to query the database directly to display data on your webpage.
This is not always possible though. If my database
runs on port 5555 then this means that my webpage will need access
to port 5555 on my server. It's not always possible if firewalls
are in the way. We know at least that port 80 should always be accessible. For several security reasons too, we might want the CouchDB to be
hidden behind the public network and only accessible by the web server internally. Just as we would do with a SQL server.

Retrieving attachments

Let's say we have an attachment that can be reachable at http://couchdbServer/database1/document1/image1.jpg.
If "document1" is a blog post that show "image1", it is tempting to put a <img src=database1/document1/image1.jpg >
But this is impossible, because that server is inaccessible from the outside world. So we might wanna do a proxy script: