How to access resultCount in N1QL Query in PHP SDK

I am wondering if anyone knows how to access the N!QL Metrics in 3.2 PHP SDK. In @.X it was via
result->metrics[‘resultCount’] but that no longer works and 3.2 has no docs on how to access that in the N1QL section.

I believe this is covered in the API Reference for Query Result. The QueryMetaData object return has metrics() which is a string/value list. This is necessary because the N1QL results are not always uniform. The results can vary based on the statement and the input arguments.

Ok looking at this part of the docs which i dont know why they wouldnt be part of the main docs like I said in past the old way was to do $result->metrics() but that’s no longer valid and one should be able to find some sample or docs how to access metrics in 3.2.

Ok I can get the metrics via $result->metaData()->metrics() but there is no info on how to get a specific element of metrics, even the new docs don’t list them.

Don’t get me wrong its not against you but i feel that your doc people are quite overrated as i found more then a handful of issues over past years

Feedback accepted and I’ll bring this up with the docs folks. In the last 18 months or so, we’ve added more resources to docs team covering SDKs and one of the things that, I agree, we’d like to do is better cross-referencing from the docs to the API reference.

Just for kicks here is another sample on missing in docs. In 2.x you got the result like this if you knew it was a single record.


now in 3.x it changed and yo need to use


Yes one can figure it out but it should not be the case that you have to dig all over and debug stuff to see why and how to do it after a change in the SDKPreformatted text

Thanks for the docs feedback @aponnath!

The main docs for Query should indeed mention ->metrics and link to the API doc Matt mentioned. There is a (very brief) sample in docs-sdk-php/query.php at release/3.2 · couchbase/docs-sdk-php · GitHub but it’s not included in the doc… Will add this now.

The $dbResult->rows()[0][‘ModificationTimestamp’] change you mentioned does have examples of the changes in Migrating from SDK2 to SDK3 API | Couchbase Docs but it could be better called out.
I’ll do a quick iteration, and ticket some additional work - any specific suggestions on how to make this clearer for a PHP specialist are welcome.

@ hakim.cassimally
i wont argue that it was not documented somewhere but in some cases it could be better / more clear where to find the info.
Interesting some of your other SDK’s have a better doc and samples with explanations so i wonder wouldn’t it be ideal to create one great master doc and then have each sdk group change it to its specific syntax ? That way it would be easy to look up a function in your docs and get all SDK specific info.

@aponnath absolutely agree - making the right decisions about where and how to document things is our biggest challenge! We do try to iterate on them, and we really appreciate the specific feedback.

Very interesting point about the master doc. I’ve mentioned to the team.

(We do try to share content where relevant, but in many cases, SDKs do things so differently – async, error handling, and so on – that it’s not always helpful to approach them in the exact same way.)

You can use result count to verify how many times a specific list entry appears in a list, or to verify how many attachments a response contains. … In the Value drop-down menu, enter ResultCount == Set the ActionMode to Verify.

Not sure your comment has anything to do with the topic here, not sure where we start talking of a dropdown