\CouchbaseAnalyticsQuery

Represents a Analytics query (currently experimental support).

Summary

Methods
Properties
Constants
fromString()
positionalParams()
namedParams()
rawParam()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

fromString()

fromString(string  $statement) : \Couchbase\AnalyticsQuery

Creates new AnalyticsQuery instance directly from the string.

Parameters

string $statement

statement string

Returns

\Couchbase\AnalyticsQuery

Examples

<?php
$cluster = new \Couchbase\Cluster('couchbase://localhost?detailed_errcodes=1');
$cluster->authenticateAs('Administrator', 'password');
$bucket = $cluster->openBucket('default');

$query = \Couchbase\AnalyticsQuery::fromString('
    SELECT "Hello, " || $name || "!" AS greeting,
           "¡Hola, " || ? || "!" AS saludo
');
$query->namedParams(['name' => 'Beer']);
$query->positionalParams(['Cerveza']);
$res = $bucket->query($query);
var_dump($res->rows[0]);
//=> object(stdClass)#5 (2) {
//     ["greeting"]=>
//     string(12) "Hello, Beer!"
//     ["saludo"]=>
//     string(16) "¡Hola, Cerveza!"
//   }

positionalParams()

positionalParams(array  $params) : \Couchbase\AnalyticsQuery

Specify array of positional parameters

Previously specified positional parameters will be replaced. Note: carefully choose type of quotes for the query string, because PHP also uses $ (dollar sign) for variable interpolation. If you are using double quotes, make sure that N1QL parameters properly escaped.

Parameters

array $params

Returns

\Couchbase\AnalyticsQuery

Examples

<?php
$cluster = new \Couchbase\Cluster('couchbase://localhost?detailed_errcodes=1');
$cluster->authenticateAs('Administrator', 'password');
$bucket = $cluster->openBucket('default');

$query = \Couchbase\AnalyticsQuery::fromString('
    SELECT "Hello, " || $name || "!" AS greeting,
           "¡Hola, " || ? || "!" AS saludo
');
$query->namedParams(['name' => 'Beer']);
$query->positionalParams(['Cerveza']);
$res = $bucket->query($query);
var_dump($res->rows[0]);
//=> object(stdClass)#5 (2) {
//     ["greeting"]=>
//     string(12) "Hello, Beer!"
//     ["saludo"]=>
//     string(16) "¡Hola, Cerveza!"
//   }

namedParams()

namedParams(array  $params) : \Couchbase\AnalyticsQuery

Specify associative array of named parameters

The supplied array of key/value pairs will be merged with already existing named parameters. Note: carefully choose type of quotes for the query string, because PHP also uses $ (dollar sign) for variable interpolation. If you are using double quotes, make sure that N1QL parameters properly escaped.

Parameters

array $params

Returns

\Couchbase\AnalyticsQuery

Examples

<?php
$cluster = new \Couchbase\Cluster('couchbase://localhost?detailed_errcodes=1');
$cluster->authenticateAs('Administrator', 'password');
$bucket = $cluster->openBucket('default');

$query = \Couchbase\AnalyticsQuery::fromString('
    SELECT "Hello, " || $name || "!" AS greeting,
           "¡Hola, " || ? || "!" AS saludo
');
$query->namedParams(['name' => 'Beer']);
$query->positionalParams(['Cerveza']);
$res = $bucket->query($query);
var_dump($res->rows[0]);
//=> object(stdClass)#5 (2) {
//     ["greeting"]=>
//     string(12) "Hello, Beer!"
//     ["saludo"]=>
//     string(16) "¡Hola, Cerveza!"
//   }

rawParam()

rawParam(string  $key,   $value) : \Couchbase\AnalyticsQuery

Specify custom parameter for query

This function exists as escape hatch for cases when the Server has implemented some new query feature, while the SDK hasn't yet exposed the API on query object yet. The key must be a string, and param is JSON-serializable object.

Parameters

string $key
$value

Returns

\Couchbase\AnalyticsQuery