/** * Executes a view query. * * @param ViewQuery $queryObj * @return mixed * @throws CouchbaseException * * @internal */ public function _view($queryObj, $json_asarray) { $path = $queryObj->toString(); $res = $this->me->http_request(1, 1, $path, NULL, 1); $out = json_decode($res, $json_asarray); if (isset($out['error'])) { throw new CouchbaseException($out['error'] . ': ' . $out['reason']); } return $out; }
/** * Executes a view query. * * @param ViewQuery $queryObj * @return CouchbaseResult * @throws CouchbaseException * * @internal */ public function _view($queryObj, $json_asarray) { $path = $queryObj->toString(); $res = $this->me->http_request(1, 1, $path, NULL, 1); $out = json_decode($res, $json_asarray); if ($json_asarray) { if (isset($out['error'])) { throw new CouchbaseException($out['error'] . ': ' . $out['reason']); } $rows = $out['rows']; $total = $out['total_rows']; } else { if (isset($out->error)) { throw new CouchbaseException($out->error . ': ' . $out->reason); } $rows = $out->rows; $total = $out->total_rows; } return new CouchbaseResult($rows, $total); }
/** * Performs a N1QL query. * * @param $dmlstring * @return mixed * @throws CouchbaseException * * @internal */ public function _n1ql($queryObj) { $data = json_encode($queryObj->toObject()); if ($this->queryhosts) { $hostidx = array_rand($this->queryhosts, 1); $host = $this->queryhosts[$hostidx]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://' . $host . '/query'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data))); $res = curl_exec($ch); curl_close($ch); } else { $res = $this->me->http_request(3, 2, NULL, $data, 1); } $resjson = json_decode($res, true); if (isset($resjson['errors'])) { throw new CouchbaseException($resjson['errors'][0]['msg'], 999); } return $resjson['results']; }
/** * Retrieves bucket status information * * Returns an associative array of status information as seen * by the cluster for this bucket. The exact structure of the * returned data can be seen in the Couchbase Manual by looking * at the bucket /info endpoint. * * @return mixed The status information. */ public function info() { $path = "/pools/default/buckets/" . $this->_name; $res = $this->_me->http_request(2, 1, $path, NULL, 2); return json_decode($res, true); }