Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Develop
  • Deploy
  • Get Help
  • Community
  • Documentation
  • Resource Library
  • English English
  • 日本語 日本語
Home | Couchbase PHP 1.1 Preview: Views

Couchbase PHP 1.1 Preview: Views

Note: The releases tagged with -dp are Developer Previews. We are excited to share our technology as early as possible with you, but at this point, we do not recommend running Developer Previews in production. Expect things to break and change in the future. That said, for the PHP SDK, we are currently only adding View functionality for Couchbase Server 2.0, and that is subject to change, everything that is in the 1.0.x release line is considered stable.

Download and Installation

See the right sidebar for your download options.  Note that a prerequisite for installation of this client library is the C client library.

After download, unpack the archive:

$ tar xzf php-ext-couchbase-$system-$arch.tar.gz

The resulting directory includes a file called couchbase.so that is the PHP extension for your system.

Edit your php.ini to include this line:

 extension=/path/to/couchbase.so

To find where your php.ini file is, try php -i | grep couchbase or look at your <?php phpinfo() ?> output.

First Run

Create this PHP script. It gets you started in three little steps:

<?php
// adjust these parameters to match your installation
$cb = new Couchbase("127.0.0.1:8091", "user", "pass", "default");
$cb->set("a", 1);
var_dump($cb->get("a"));
?>

The line with new Couchbase() establishes a connection to our Couchbase Server installation and gives us access to the Couchbase Server API. Next, we set the value of the key "a" to 1. Finally, we get the value for our key "a" and print it out. When you run this script, it should print int(1).

View Support

<?php
$cb = new Couchbase("127.0.0.1:8091", "user", "pass", "default");
$result = $cb->view("design_doc", "view_name");
foreach($result["rows"] as $row) {
  echo $row->key;
}
The view() method takes the design document and view name as arguments that you specified in the Couchbase Server 2.0 Administration interface. It returns a result set that you can iterate over to get your view results. There is of course a corresponding couchbase_view() function.
 
If you don't have a view set up yet, but want to play with this interface, you can use the built-in "_all_docs" view:
<?php
$cb = new Couchbase("127.0.0.1:8091", "user", "pass", "default");
$result = $cb->view("_all_docs", "");
foreach($result["rows"] as $row) {
  echo $row->key;
}
 
To pass options to the view query, you need to treat the view name as an URL enpoint and add options to it like you would in a browser. This is a preliminary API and will be made more comfortable to user very soon.
$result = $cb->view("design_doc", "view_name?include_docs=true");

 

For more information, please see the Getting Started Guide.

Support

If you have any questions, problems or suggestions, please let us know on the Couchbase SDK forums.

PHP SDK 1.1.0-dp1

We provide binary downloads for a select number of systems, if yours is missing, please let us know in the forums.

  • Centos 5.2, 32-bit
    (RedHat and Fedora compatible).
  • Centos 5.2, 64-bit
    (RedHat and Fedora compatible).
  • Ubuntu 9.04, 32-bit
    (10.x compatible, Debian compatible).
  • Ubuntu 9.04, 64-bit
    (10.x compatible, Debian compatible).
  • Mac OS X 10.6 64 bit.
  • Fork us on GitHub

Documentation

  • Getting Started
  • Tutorial
  • API Reference

 

Product

  • Couchbase Server 1.8
  • Couchbase Server 2.0
  • Memcached and Couchbase Server
  • Looking for CouchDB?
  • Looking for Membase?

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Careers
  • Blog
  • Contact Us

News & Events

  • Press Releases
  • Buzz
  • Events
  • CouchConf

Community

  • Forums
  • Wiki
  • Contribute
  • Gear

Engage With Us

  • Subscriptions and Support
  • Training and Services
  • Subscribe to our Newsletter
  • Buy Now

Follow Us

 

  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

Copyright Couchbase 2012