How to do prepared statement with n1ql?

n1ql

#1

Hello,

Looking at the documentation at http://developer.couchbase.com/documentation/server/4.0/sdks/dotnet-2.2/prepared-statements.html, 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?


#2

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


#3

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.