Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php namespace CouchBaseWrapper;
- use CouchbaseCluster;
- class CouchDB {
- private $couchClient;
- private $couchBucket;
- private function openConection(){
- try{
- $this->couchClient = new CouchbaseCluster(<COUCH_HOST>);
- $this->couchBucket = $this->couchClient->openBucket(<COUCH_BUCKET>);
- }
- catch (Exception $e) {
- echo $e;
- }
- return true;
- }
- function getKey($k) {
- try{
- if(!$this->openConection()) { return false; }
- $res = $this->couchBucket->get($k);
- $data_rcvd = $res->value;
- }
- catch(Exception $e){
- echo $e;
- }
- echo "Outter Code";
- return $data_rcvd;
- }
- }
- ?>
- <?php namespace CouchBaseWrapper
- ini_set("display_errors", true);
- require_once('couchbaseWrapper.php');
- $cb = new CouchDB();
- $result = $cb->getKey("non-existing-key"); // <== Error
- //$result = $cb->getKey("existing-key"); // <== Existing key No error
- var_dump($result);
- ?>
- public function exists($key) {
- if(!$this->openConection()) { return false; }
- return $this->couchBucket->get($key) == NULL
- && $this->couchBucket->getResultCode() == COUCHBASE_KEY_ENOENT;
- }
- try{
- // ...
- }
- catch(Exception $e){
- echo $e;
- }
- try{
- // ...
- }
- catch(CouchBaseWrapperException $e){
- echo $e;
- }
- try{
- // ...
- }
- catch(Exception $e){
- echo $e;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement