How to do prepared statement with n1ql?


Looking at the documentation at, there is a way to use prepared statement.

How do I use a prepared statement in php SDK?

If it is not currently supported, what’s the best way to get around it?

$query = \CouchbaseN1qlQuery::fromString(‘SELECT * from default where type=$type LIMIT $length’);
$res = $bucket->query($query, array(‘type’ => $type, ‘length’ => (int)$length);

Hi jarro,

sorry for the delay in response.

That actually didn’t work for me. I tested it with very simple query.

$q = CouchbaseN1qlQuery::fromString(‘select * from mybucket LIMIT $length’);
$res = $bucket->query($q, [
‘length’ => 3,

I got “Unrecognized parameter in request: 0”

Update 1:

I removed couchbase sdk and then re-built it by cloning the master branch from github. It works as expected now.