# Check for key exists in the database

**URL:** <https://discuss.aerospike.com/t/check-for-key-exists-in-the-database/3678>\
**Category:** PHP Client Library\
**Created:** [December 10, 2016, 9:25pm UTC](https://discuss.aerospike.com/t/check-for-key-exists-in-the-database/3678 "2016-12-10T21:25:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![serghei](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/serghei/32/671_2.png) [@serghei](https://discuss.aerospike.com/u/serghei)\
**Post date:** [December 10, 2016, 9:25pm UTC](https://discuss.aerospike.com/t/check-for-key-exists-in-the-database/3678/1 "2016-12-10T21:25:51Z")

</div>

Hey there. Could you please explain why the `Aerospike::exists` method throws **Fatal Error** :

```php
$aerospike = new \Aerospike(
    [
        'hosts' => [
            ['addr' => '127.0.0.1', 'port' => 3000]
        ],
        'shm' => [],
    ],
    false,
    []
);

$bins = ['value' => 99];
$akey = $aerospike->initKey('test', 'cache', 'test-data');

$putStatus = $aerospike->put(
    $akey,
    $bins,
    0,
    [\Aerospike::OPT_POLICY_KEY => \Aerospike::POLICY_KEY_SEND]
);
var_dump($putStatus); // \Aerospike::OK here

$deleteStatus = $aerospike->remove($akey);
var_dump($deleteStatus); // \Aerospike::OK here

$existsStatus = $aerospike->exists($akey, $metadata); // Fatal error

```

```auto
$ php aerospike.php
/tmp/aerospike.php:24:
int(0)
/tmp/aerospike.php:27:
int(0)
PHP Fatal error: Aerospike::exists(): exists/getMetadata: 
    unable to fetch the record in /tmp/aerospike.php on line 29
PHP Stack trace:
PHP 1. {main}() /tmp/aerospike.php:0
PHP 2. Aerospike->exists() /tmp/aerospike.php:29

```

```auto
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.1 LTS
Release:	16.04
Codename:	xenial

```

```auto
$ php -v
PHP 7.0.13-1+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.13-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

```

```auto
$ php --ri aerospike

aerospike

aerospike support => enabled
aerospike version => 3.4.13

```

Docker Image `aerospike:3.10.1`

---

<div class="post-metadata">

**Author:** ![serghei](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/serghei/32/671_2.png) [@serghei](https://discuss.aerospike.com/u/serghei)\
**Post date:** [December 10, 2016, 10:02pm UTC](https://discuss.aerospike.com/t/check-for-key-exists-in-the-database/3678/2 "2016-12-10T22:02:23Z")

</div>

Well, I found in [src/aerospike/aerospike\_record\_operations.c](https://github.com/aerospike/aerospike-client-php/blob/master/src/aerospike/aerospike_record_operations.c#L1450):

```nohighlight
if (AEROSPIKE_OK != (status = aerospike_record_operations_exists(as_object_p, &as_key_for_put_record, error_p, metadata_p, options_p TSRMLS_CC)))
{
    DEBUG_PHP_EXT_ERROR("exists/getMetadata: unable to fetch the record");
    goto exit;
}

```

and in [`src/aerospike/aerospike_common.h`](https://github.com/aerospike/aerospike-client-php/blob/master/src/aerospike/aerospike_common.h#L476)

```nohighlight
#define DEBUG_PHP_EXT_ERROR(args...) DEBUG_PHP_EXT_COMPARE_LEVEL(AS_LOG_LEVEL_ERROR, E_ERROR, args)

#define DEBUG_PHP_EXT_COMPARE_LEVEL(log_level, php_log_level, args...) \
do { \
    if (!(((as_log_level) PHP_EXT_AS_LOG_LEVEL_OFF) == php_log_level_set)) \
        if (php_log_level_set >= log_level) { \
            php_error_docref(NULL TSRMLS_CC, php_log_level, args); \
            aerospike_helper_log_callback((log_level | 0x08), __func__ TSRMLS_CC, \
                    __FILE__ , __LINE__ , ##args); \
        } \
} while(0)

```

but still in some confusion

---

<div class="post-metadata">

**Author:** ![serghei](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/serghei/32/671_2.png) [@serghei](https://discuss.aerospike.com/u/serghei)\
**Post date:** [December 10, 2016, 11:47pm UTC](https://discuss.aerospike.com/t/check-for-key-exists-in-the-database/3678/3 "2016-12-10T23:47:19Z")

</div>

Fixed by compiling the php client with the following flags:

```nohighlight
CFLAGS="-std=gnu99 -g -D __AEROSPIKE_PHP_CLIENT_LOG_LEVEL__ =PHP_EXT_AS_LOG_LEVEL_OFF"

```
