A newer version of this documentation is available.

View Latest

Working with N1QL queries

You can perform Couchbase Query Language (N1QL) queries via the PHP SDK.

To send N1QL queries, you must specify a list of application query hosts through the enableN1ql()method (a temporary necessity). After you have done this, you can perform a N1QL query by using the query() method, which accepts a query created through the CouchbaseN1qlQuery class. You receive an array of objects representing the results.

The following example shows how to send a N1QL query:

$myBucket = $myCluster->openBucket();
$query = CouchbaseN1qlQuery::fromString('SELECT * FROM default');
$res = $myBucket->query($query);

Sample output from the example:

array(2) {
  array(1) {
  array(1) {