bashar
May 26, 2016, 12:43pm
1
I have this example where the results contains only the rows, how to find metrics where I need to get rows count of all results
$myBucket = $myCluster->openBucket();
$myBucket->enableN1ql(array('http://1.1.1.1:8093/','http://1.1.1.2:8093/'));
$query = CouchbaseN1qlQuery::fromString('SELECT * FROM default limit 10');
$res = $myBucket->query($query);
var_dump($res);
anybody can help please ?!
avsej
May 26, 2016, 1:37pm
2
@bashar , this functionality is not exposed yet, but if you like, you can use the following approach now (note that it is using internal interfaces, which are private and might change without notice)
$r = new ReflectionClass('CouchbaseBucket');
$private_interface = $r->getProperty('me');
$private_interface->setAccessible(true);
$h = new CouchbaseCluster('couchbase://localhost');
$b = $h->openBucket('travel-sample');
$query = json_encode(CouchbaseN1qlQuery::fromString('SELECT * FROM `travel-sample` limit 10')->toObject(), true);
$res = $private_interface->getValue($b)->n1ql_request($query, true);
$meta = json_decode($res['meta'], true);
$rows = array();
foreach ($res['results'] as $row) {
$rows[] = json_decode($row, true);
}
var_dump($meta);
var_dump(count($rows));