Getting message "[message:protected] => adhoc must be a bool"?


#1

Hello guys,

I am totally new to couchbase, so help me if there anything wrong I did.

I’m using C-SDK (2.5.7 64-bit) and PHP-SDK (2.0.0) to populate data in/from Couchbase server.

Note:- [I’m using **RHEL** server **6.x** and **PHP 5.6.12**. Due to network security I’m unable to install directly using ‘**wget**’ or ‘**PECL**’ command. So I download the **C-SDK** zip and install all the rpm files and then I installl the **PHP-SDK** by downloading the source file and compile it manually.]

The code is working fine for basic CRUD operation using get,insert,update functions. But it’s unable to work when I’m trying to execute N1QL query.

The php code I’m using to achieve this is as follow:-

try {
        $myCluster= new CouchbaseCluster("http://X.X.X.X");
        $myBucket = $myCluster->openBucket("default");
        $query = CouchbaseN1qlQuery::fromString("SELECT * FROM default");
        $res = $myBucket->query($query);
}catch(CouchbaseException $e){
        print_r($e);
}

Now I’m getting exception with detail message like this :-

CouchbaseException Object
(
    [message:protected] => adhoc must be a bool
    [string:Exception:private] =>
    [code:protected] => 7
    [file:protected] => [CouchbaseNative]/CouchbaseBucket.class.php
    [line:protected] => 313
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => [CouchbaseNative]/CouchbaseBucket.class.php
                    [line] => 313
                    [function] => n1ql_request
                    [class] => _CouchbaseBucket
                    [type] => ->
                    [args] => Array
                        (
                            [0] => {"statement":"SELECT * FROM default"}
                            [1] => 1
                        )

                )

            [1] => Array
                (
                    [file] => [CouchbaseNative]/CouchbaseBucket.class.php
                    [line] => 342
                    [function] => _n1ql
                    [class] => CouchbaseBucket
                    [type] => ->
                    [args] => Array
                        (
                            [0] => CouchbaseN1qlQuery Object
                                (
                                    [options] => Array
                                        (
                                            [statement] => SELECT * FROM default
                                        )

                                    [adhoc] => 1
                                )

                            [1] =>
                            [2] =>
                        )

                )

            [2] => Array
                (
                    [file] => /home/super/phpsqltest.php
                    [line] => 8
                    [function] => query
                    [class] => CouchbaseBucket
                    [type] => ->
                    [args] => Array
                        (
                            [0] => CouchbaseN1qlQuery Object
                                (
                                    [options] => Array
                                        (
                                            [statement] => SELECT * FROM default
                                        )

                                    [adhoc] => 1
                                )

                        )

                )

        )

    [previous:Exception:private] =>
)

Please help…


#2

Hi @cihangirb, any suggestions?


#3

This seems like some incompatibility between the libcouchbase and PHP in use. It could be something that autoboxed in other PHP distributions didn’t do so here. Maybe @avsej or @mnunberg have more insight into why the default adhoc is being rejected. You may be able to override it by specifying a PHP boolean for the adhoc param (see the API reference linked off of the current documentation).

Is there any reason you chose the 2.0.0 extension? That appears to be about 18 months old. The 2.1 series is the current stable release.

We’re getting ready to issue a new version of the extension under the 2.2 series with improvements in PHP support around PHP 7, support for Couchbase Server 4.5 features and of course many bug fixes. Might you be able to try that one? The source can be cloned from github or downloaded as a zip file.

If you’re starting a new project, that may be the best extension to use, since it’ll likely be released by the time your development is complete.


#4

It would appear that the default n1qlQuery is passing adhoc as 1 rather than true, resulting in the error. This doesn’t have anything to do with the C SDK, and would appear to be a bug in the PHP SDK version being used, though it seems that https://github.com/couchbase/php-couchbase/blob/master/phpstubstr.h#L859 will coerce any adhoc parameter to a boolean. Any ideas @brett19 ?


#5

Thanks for your response. Hope it will be helpful for us. Bdw the series is 2.0/2.1.


#6

Hello @mnunberg, we also dig that problem already. But I guess adhoc properties is going to be set inside fromString function i.e.

 static public function fromString($str) {
        $res = new CouchbaseN1qlQuery();
        $res->options['statement'] = $str;
        $res->adhoc = true;
        return $res;
    }

and this function is called from my PHP code as you can see above i.e.

$query = CouchbaseN1qlQuery::fromString("SELECT * FROM default");

Please correct me if I’m wrong.


#7

Hello @ingenthr, I again install the beta version of PHP SDK i.e. v2.2.0beta1.tar.gz but the problem is not intact.


#8

++info

If I keep a var_dump for CouchbaseN1qlQuery class in my php code, like this

try {
        $myCluster= new CouchbaseCluster("http://X.X.X.X");
        $myBucket = $myCluster->openBucket("default");
        $query = CouchbaseN1qlQuery::fromString("SELECT * FROM default");
        //See here
        var_dump($query);
        $res = $myBucket->query($query);
}catch(CouchbaseException $e){
        print_r($e);
}

then the following structure I can see in output,

object(CouchbaseN1qlQuery)#4 (2) {

  ["options"]=>

  array(1) {

    ["statement"]=> string(21) "SELECT * FROM default"

  }

  ["adhoc"]=> bool(true)

}
............................
..........................
........................
....................

#9

I’m sorry, but I don’t understand what you mean by “the problem is not intact”. Can you clarify? Was it solved, or is the issue still there when using the build from the master branch from which we’ll release 2.2?


#10

No, we are still facing the same problem.


#11

Hi @Chi

Thanks for report, the issue has been fixed in http://review.couchbase.org/63206, and will be released with next beta.


#12

Thank you @avsej, I am waiting for the next release.:relaxed: