Advertisement
Guest User

Untitled

a guest
May 6th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php namespace CouchBaseWrapper;
  2. use CouchbaseCluster;
  3.  
  4. class CouchDB {
  5. private $couchClient;
  6. private $couchBucket;
  7.  
  8. private function openConection(){
  9. try{
  10. $this->couchClient = new CouchbaseCluster(<COUCH_HOST>);
  11. $this->couchBucket = $this->couchClient->openBucket(<COUCH_BUCKET>);
  12. }
  13. catch (Exception $e) {
  14. echo $e;
  15. }
  16. return true;
  17. }
  18.  
  19. function getKey($k) {
  20. try{
  21. if(!$this->openConection()) { return false; }
  22.  
  23. $res = $this->couchBucket->get($k);
  24. $data_rcvd = $res->value;
  25. }
  26. catch(Exception $e){
  27. echo $e;
  28. }
  29. echo "Outter Code";
  30. return $data_rcvd;
  31. }
  32.  
  33. }
  34. ?>
  35.  
  36. <?php namespace CouchBaseWrapper
  37.  
  38. ini_set("display_errors", true);
  39.  
  40. require_once('couchbaseWrapper.php');
  41.  
  42. $cb = new CouchDB();
  43. $result = $cb->getKey("non-existing-key"); // <== Error
  44. //$result = $cb->getKey("existing-key"); // <== Existing key No error
  45.  
  46. var_dump($result);
  47. ?>
  48.  
  49. public function exists($key) {
  50. if(!$this->openConection()) { return false; }
  51. return $this->couchBucket->get($key) == NULL
  52. && $this->couchBucket->getResultCode() == COUCHBASE_KEY_ENOENT;
  53. }
  54.  
  55. try{
  56. // ...
  57. }
  58. catch(Exception $e){
  59. echo $e;
  60. }
  61.  
  62. try{
  63. // ...
  64. }
  65. catch(CouchBaseWrapperException $e){
  66. echo $e;
  67. }
  68.  
  69. try{
  70. // ...
  71. }
  72. catch(Exception $e){
  73. echo $e;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement