dready92 / php-on-couch Goto Github PK
View Code? Open in Web Editor NEWData Access Library to access a CouchDB server with PHP.
Home Page: http://dready.byethost31.com/index.php/display/view/192
License: GNU Lesser General Public License v3.0
Data Access Library to access a CouchDB server with PHP.
Home Page: http://dready.byethost31.com/index.php/display/view/192
License: GNU Lesser General Public License v3.0
Please, fix.
<?php
public function record() {
foreach ( couchClient::$underscored_properties_to_remove_on_storage as $key ) {
if ( property_exists($this->__couch_data->fields,$key) ) {
unset( $this->__couch_data->fields->$key );
}
}
$response = $this->__couch_data->client->storeDoc($this->__couch_data->fields);
$this->__couch_data->fields->_id = $response->id;
$this->__couch_data->fields->_rev = $response->rev;
/****** SUPPOSED TO RETURN $response RIGHT HERE ********/
}
You try to define a map this way:
$view_fn="function(doc) { emit(doc.timestamp,null); }"; //<- no map key here!
$design_doc->views = array ( 'by_date',$view_fn); //<- so, this won't work!
because the map key is missing, so $view_fn must be an array!
I use this definition and it works as expected:
$view_fn=array( 'map' => 'function(doc) { emit(doc.timestamp,null); }');
$design_doc->views = array ( 'by_date',$view_fn);
Great piece of work, thank you very much for githubbing without your work I'd be lost...
I implemented a simple but useful _ensure_full_commit method. See http://docs.couchone.com/couchdb-api/couchdb-api-db.html#couchdb-api-db_db-ensure-full-commit_post . Could it be included upstream? Thanks.
P. S.: Docs say it returns http code 200 yet I get 201 (CouchDb 1.0.1.)
/**
* Synchronize database to disc
*
* @return object CouchDB document storage response
*/
public function ensureFullCommit()
{
$method = 'POST';
$url = '/' . urlencode($this->dbname) . '/_ensure_full_commit';
return $this->_queryAndTest($method, $url, array(200, 201), array());
}
The argument $commit
is ignored, instead, true is always used here. The documentation shows: @param boolean $commit turn on or off the autocommit feature
Similarly to a previous issue, there may in fact be multiple HTTP/1.1 100 Continue sections preceding the HTTP response. I have encountered this behaviour when couchdb is behind an http proxy. A simple solution; Line 99 of couch.php just needs to be changed from 'if' to 'while':
while ( !substr_compare($raw_data, "HTTP/1.1 100 Continue\r\n\r\n", 0, 25) ) {
$raw_data = substr($raw_data, 25);
}
Hi,
I read http://github.com/dready92/PHP-on-Couch/blob/master/doc/couch_client-view.md to create a view but the section:
$view_fn="function(doc) { emit(doc.timestamp,null); }";
$design_doc->_id = '_design/all';
$design_doc->language = 'javascript';
$design_doc->views = array ( 'by_date',$view_fn);
$client->storeDoc($design_doc);
should be:
$view_fn="function(doc) { emit(doc.timestamp,null); }";
$design_doc->_id = '_design/all';
$design_doc->language = 'javascript';
$design_doc->views = array ( 'by_date' => 'map' => $view_fn);
$client->storeDoc($design_doc);
otherwise it will not really create a view
I don't know if it's an issue or not but i can't find a way do it using your api.
As described here: http://wiki.apache.org/couchdb/HTTP_view_API , couchdb accepts a keys value in POST, but getView doesnt support it. the below implementation of the method does.
/**
* request a view from the CouchDB server
*
* @link http://wiki.apache.org/couchdb/HTTP_view_API
* @param string $id design document name (without _design)
* @param string $name view name
* @param array $keys optionally, a list of keys to return (instead of using the other query options)
* @return object CouchDB view query response
*/
public function getView ( $id, $name, $keys = array()) {
if ( !$id OR !$name ) throw new InvalidArgumentException("You should specify view id and name");
$url = '/'.urlencode($this->dbname).'/_design/'.urlencode($id).'/_view/'.urlencode($name);
if ( $this->results_as_cd ) $this->include_docs(true);
$view_query = $this->view_query;
$results_as_cd = $this->results_as_cd;
$this->view_query = array();
$this->results_as_cd = false;
$method = 'GET';
$data = NULL;
if ( count($keys) ) {
$method = 'POST';
$data = json_encode(array('keys'=>$keys));
}
if ( ! $results_as_cd )
return $this->_queryAndTest ($method, $url, array(200),$view_query, $data);
return $this->resultsToCouchDocuments (
$this->_queryAndTest ($method, $url, array(200),$view_query, $data)
);
}
Documentation says:
To retrieve several documents in one go, knowing their IDs, use the method getAllDocs($ids). $ids is an array of documents IDs. This function acts like a view, so the output is the view output of CouchDB, and you should use "include_docs(TRUE)" to have documents contents.
Example :
$view = $client->include_docs(true)->getAllDocs( array('BlogPost5676','BlogComments5676') );
foreach ( $view->rows as $row ) {
echo "doc id :".$row->doc->_id."\n";
}
Core doesn't have an argument.. :
public function getAllDocs ( ) {
$url = '/'.urlencode($this->dbname).'/_all_docs';
list($method, $view_query, $data) = $this->_prepare_view_query();
return $this->_queryAndTest ($method, $url, array(200),$view_query,$data);
}
Trying to get all revs using
$client->open_revs('all')->getDoc($id);
returns the following weirdness
--43afb13b61f1044f5713cb42ae4138b4
Content-Type: application/json
{json_data_structure}
--43afb13b61f1044f5713cb42ae4138b4--
This looks like some sort of debug output rather than the datastructure I was expecting..... Or am I missing something? Also, even with multiple revs, it only shows the latests.
Chris
HI There,
is there option to change password with this API ?
Thanks
Sid
If the password contains @ (example: pass@word) this happens:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'no data to parse' in /home/noname/.web/couchdbtest/lib/couch.php:138 Stack trace: #0 /home/noname/.web/couchdbtest/lib/couchClient.php(152): couch::parseRawResponse(false, false) #1 /home/noname/.web/couchdbtest/lib/couchClient.php(261): couchClient->_queryAndTest('GET', '/test', Array) #2 /home/noname/.web/couchdbtest/lib/couchClient.php(302): couchClient->getDatabaseInfos() #3 /home/noname/.web/couchdbtest/index.php(8): couchClient->databaseExists() #4 {main} thrown in /home/noname/.web/couchdbtest/lib/couch.php on line 138
Without @ (example : password) works.
Description of the view I created:
_id for the document created this way:
"_id": "verband/regional/landes/kreis/staffel"
so, there is the possibility that an _id looks like this:
"_id": "verband/staffel"
So I created a view using this RegEx:
/^[a-z/]+(?![A-Za-z0-9-]+)/
which matches lower-keys and a slash until an expression having defenitely no slash.
If I take a look at Futon running the view I get a response and the key section's looking fine apart of the fact that it seems to be an array - why that?
["verband/regional/landes/kreis"]
So, if I directly put this to an URL with the key wrapped like this:
?key=["verband/regional/landes/kreis"]
the browser shows me what I want and the log shows me this:
[Sun, 09 Jan 2011 09:32:11 GMT] [info] [<0.20686.49>] 88.130.208.94 - - 'GET' /staffel(2010-2011)/_design/show/_view/like?key=[%22dhb/shv/baden/karlsruhe%22] 304
complete view script:
function(doc) {
if(doc._id) {
// from the start (^) match everything that has lower case characters and a slash
// as many times possible [a-z]+ until finding a match without a slash which is dropped
// (?![A-Za-z0-9-]+)
var prefix = doc._id.match(/^[a-z/]+(?![A-Za-z0-9-]+)/);
if(prefix) {
emit(prefix,doc);
}
}
}
This is my humble opinion.
You're licensing your code under GPL. It happens that without a linking exception your code is unsuitable to be linked with software that uses another license what does cause it to be less used than it could be.
For example, it forbidden one to make a BSD code using your library to connect to CouchDB.
As a solution for that I recommend you either license it under a license which allows linking more freely such as the new BSD, MIT's. You can also either use LGPL or add a linking exception permitting the linking.
More on the linking exception: http://en.wikipedia.org/wiki/GPL_linking_exception
I'm using last version of your code.
code to update document
$doc=$this->couch->asCouchDocuments()->getDoc($object->get_Id());
$doc->name=$object->name;
$resp=$this->couch->storeDoc($doc);
Document has been updated but the following exception was thrown:
Uncaught exception 'couchException' with message 'Conflict - Document update conflict.' in /var/www/html/test_couch/classes/couchClient.php:129
Stack trace:
#0 /var/www/html/test_couch/classes/couchClient.php(412): couchClient->_queryAndTest('PUT', '/test/935f3d62d1...', Array, Array, Object(couchDocument))
#1 /var/www/html/test_couch/classes/TestCouch.php(201): couchClient->storeDoc(Object(couchDocument))
#2 /var/www/html/test_couch/classes/TestCouch.php(177): TestCouch->UpdateObject(Object(Location))
#3 /var/www/html/test_couch/classes/go.php(10): TestCouch->UpdateLocation(Object(Location))
#4 {main}
CouchDB has a function for temp Views, so you can send a function to the server and get the result, without store the view.
Example:
curl -H 'Content-Type: application/json' -X POST http://localhost:5984/example/_temp_view -d '{"map" : "function(doc) { if (doc.kdnr) { emit(doc.kdnr, doc.licencse); } }"}'
It is possible to implement this and get an array of docs back?
If the password contains @ (example: pass@word) this happens:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'no data to parse' in /home/noname/.web/couchdbtest/lib/couch.php:138 Stack trace: #0 /home/noname/.web/couchdbtest/lib/couchClient.php(152): couch::parseRawResponse(false, false) #1 /home/noname/.web/couchdbtest/lib/couchClient.php(261): couchClient->_queryAndTest('GET', '/test', Array) #2 /home/noname/.web/couchdbtest/lib/couchClient.php(302): couchClient->getDatabaseInfos() #3 /home/noname/.web/couchdbtest/index.php(8): couchClient->databaseExists() #4 {main} thrown in /home/noname/.web/couchdbtest/lib/couch.php on line 138
Without @ (example : password) works.
Hey,
I'm stuck with updating a doc..
I'm creating a doc with $doc->set - supplying an array like this:
http://gist.github.com/623827
But I can't seem to find any docs on sending a doc->set with a _rev => $doc->_rev field - so it get's saved as a new revision.
Like so:
curl -X PUT http://127.0.0.1:5984/orders/ID -d '{"_rev":"1-2902191555","title":"New title", "pno":"88823","price":"199" and so forth.. }
Which would then be saved as rev 2-xxx
I'm only finding this to update fields in a document:
$doc = $client->getDoc('ID');
$doc->field = 'New stuff';
$response = $client->storeDoc($doc);
This works great, but what do I use if I want to update $doc with basically the same array as the one in the gist. In my usage case this would happen each time someone places an order. Where estoreOrderNo would be unique on each consecutive order, saving the old order when overwriting all other fields.
Php on couch does not provide a mean to populate the form attribute in Update request http://wiki.apache.org/couchdb/Document_Update_Handlers#Request.
From my observation it is required to set Content-Type to application/x-www-form-urlencoded and encode the data in appropriate way (CouchDb 1.0.1).
The couchAdmin class has the $userdb
property set to _users
. When you use a different user database, you cannot use the admin. Please add a getter/setter for this property.
Also, there are a couple of hard-coded _users
strings used, instead of the $userdb
property.
$key='mykey';
$result = $client->key($key)->getView('show','something');
is not working.
If I do it this way:
$result = $client->key('mykey')->getView('show','something');
it works.
I think there must be a way to assign a key with strings.
Strange...
Don't know if anyone else has noticed this, but sometimes posting to the server, using the try/catch statement, the request comes back as 'fail'... and the server error will say 'accepted'. In other words, the data still gets added into couchdb, but 'fails'. I'm not sure if this is an error with the script or something funky with couchdb?
It's normally not an issue, but when I'm expecting a certain json response and instead I get back an error message, it's tough to handle it when it's still a successful add to couchdb
According to RFC 2616 s4.2, HTTP header fields are case-insensitive.
The parseRawResponse method should match '@Content-Type:\s+application/json@i' <--(Note the i)
In couchClient.php:
/**
* Set all CouchDB query options at once.
* Any invalid options are ignored.
*
* @link http://wiki.apache.org/couchdb/HTTP_view_API
* @param mixed $value any json encodable thing
* @return couchClient $this
*/
public function setOptions(array $options) {
foreach($options as $option=>$v) if (array_key_exists($option,$this->query_defs))
$this->$option($v);
return $this;
}
could not get your md.examples to work. map: tag is missing. reduce: example would be nice
From 27872be5a7e82076d6a64264bbd30677e205219e Mon Sep 17 00:00:00 2001
Date: Sat, 30 Oct 2010 19:48:16 +0200
Subject: [PATCH] fix getViewInfos
lib/couchClient.php | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/couchClient.php b/lib/couchClient.php
index cbb38f6..2c3f142 100644
--- a/lib/couchClient.php
+++ b/lib/couchClient.php
@@ -788,7 +788,7 @@ class couchClient extends couch {
return $this->_queryAndTest ('GET', $url, array(200), $additionnal_parameters);
}
if ( !$id OR !$name ) throw new InvalidArgumentException("You should specify view id and name");
if ( !$id ) throw new InvalidArgumentException("You should specify view id");
I have use cases where the connection details are changed after instantiation, the following change allows this to occur (change in couch.php):
public function __construct ($dsn, $options = array() ) {
$this->setDsn($dsn);
$this->options = $options;
if ( function_exists('curl_init') ) $this->curl = TRUE;
}
public function getDsn() {
return $this->dsn;
}
public function setDsn($dsn) {
$this->dsn = preg_replace('@/+$@','',$dsn);
$this->dsn_parsed = parse_url($this->dsn);
if ( !isset($this->dsn_parsed['port']) ) {
$this->dsn_parsed['port'] = 80;
}
}
public function setUser($user, $pass) {
extract($this->dsn_parsed, EXTR_SKIP);
$dsn = "$scheme://$user:$pass@$host:$port";
if (isset($path)) $dsn.='/'.$path;
$this->setDsn($dsn);
}
moin moin,
I found your project by searching a php driver/lib for couch.
At first glance it's the best / easiest that I have found.
But something make me sad, you have no namespaces.
Is it possible to add the PSR-0 into this project?
Is it possible to connect to the couch db using https:// If I try http:// it works fine, but if I try https:// it does not?
Let me explain better, i have php on couch on codeigniter framework, so when i enter the docid pull the attachment from couchDB, but because the file is with the wrong ext i cant view the file online, but the couchDB database is big, some files are store using the wrong file ext. so i want to know if is possible manipulate CouchDB stream to render the correctly on the browser or download.
Thanks for the Advice.
In couchClient.php
/**
* request a lucene result from the CouchDB server
*
* @param string $id design document name (without _design)
* @param string $name view name
* @param string $query view query ('q=...')
* @return object CouchDB view query response
*/
public function getLuceneView ( $id, $name, $query ) {
if ( !$id OR !$name OR !$query) throw new InvalidArgumentException("You should specify design doc id, lucene view name and query");
$url = '/'.urlencode($this->dbname).'/_fti/_design/'.urlencode($id).'/'.urlencode($name);
$results_as_cd = $this->results_as_cd;
$this->results_as_cd = false;
list($method, $view_query, $data) = $this->_prepare_view_query();
$view_query['q'] = $query;
if ( !$results_as_cd )
return $this->_queryAndTest ($method, $url, array(200),$view_query,$data);
return $this->resultsToCouchDocuments (
$this->_queryAndTest ($method, $url, array(200),$view_query,$data)
);
}
It seems that the CouchAdmin class give some error on the construct.
Whe i use my client to query there's no problem, but when i create a CouchAdmin object passing the same client it gave me this:
Bad Request - Name: '_membership'. Only lowercase characters (a-z), digits (0-9), and any of the characters _, $, (, ), +, -, and / are allowed. Must begin with a letter. (GET /_membership [])
hey,
i found that the tests are not working with phpunit 3.7.x.
could you provide any information about what version you are using to run the tests?
best regards
Hi,
I'm facing this error
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64 bytes) in /home/paul/couch/lib/couch.php on line 152
I'm retrieving a huge amount of documents from my view.
Would be very nice to have support for PHP composer
Hi,
everything runs fine so far but now I run into a problem which is far beyond my knowledge about couchDB and the reduce funtions. Let me explain:
The thing I want to get out of the database is a key/value pair emitting all the clubs playing in one league.
My wish is a return from couch looking like this:
{ ["verband","landes","regional","kreis","league"]:["club1","club2",...."clubX"] }
What I am using as a view is this:
function(doc) {
if (doc.kreis ) {emit ( [doc.verband,doc.regional,doc.landes,doc.kreis,doc.staffel], doc.heim); } else {
if (doc.landes ) {emit ( [doc.verband,doc.regional,doc.landes,doc.staffel], null); } else {
if (doc.regional) {emit( [doc.verband,doc.regional,doc.staffel], null); } else {
if (doc.verband) {emit ( [doc.verband,doc.regional,doc.staffel], null); }
}
}
}
}
Which gives me the key as an array as expected, but To achieve a 'DISTINCT' like function I use this code in the reduce section:
function(keys, values) {
return true;
}
This is just a start, this code reduces the key section in a sql-distinct way, but I have 'true' as a value, but I want distinct (single) club names in an array.
To explain the way documents look like:
every document displays a handball game, and the handball-clubs appear either as a home- or a guest-team.
A loop is needed to get all clubs appearing as home or guest team in a league (which is the key) reducing them in a way, that the team only appears once in the value-array.
I try around this day, maybe I'll find a solutin, but help is appreciated...
Kind regards, Steffen
__set() calls record() every time a property is changed. This behavior might be undesired - could it be made configurable?
(I would prefer to manually save the document, so I've removed the record() call from set, and changed __set to call setOne.)
Perhaps a static flag '$auto_record', and a way to change it?
The Admin class takes an (maybe) authorised client as it's first argument.
$client = new couchClient(http://username:[email protected]:5984),'myDb');
$admin = new couchAdmin($client);
When the admin class wants to make requests it uses the DSN from $client->dsn(), however the username and password is stripped from the DSN in the __construct
of couch
class:
// couch.php line 68
$this->dsn = preg_replace('@/+$@','',$dsn);
This means that the DSN used by the admin class will not allow the object to authenticate with the database.
At the moment I am extending the client class as so:
// MyClient.php
public function __construct($dsn, $dbname, $options = array() ) {
parent::__construct($dsn, $dbname, $options);
$this->dsn = $dsn;
}
This allows any admin classes to use the 'original' DSN, and thus authenticate.
Am I misunderstanding how this should be used or is this an error?
he I want start a discussion what thinks we need and want we can implement before we make a BC break
without BC break:
need BC break:
possible for both:
please write me your ideas I will update the wanted list
regards
At the moment, all that is shown by the couchException is 'Unauthorized' or similar. (Yes, getBody() is good but it doesn't show in the usual exception display)
I suggest:
function __construct($raw_response) {
$this->couch_response = couch::parseRawResponse($raw_response);
if (is_object($this->couch_response['body']) and isset($this->couch_response['body']->reason))
$message = $this->couch_response['status_message'] . ' - ' . $this->couch_response['body']->reason;
else
$message = $this->couch_response['status_message'];
parent::__construct($message, $this->couch_response['status_code']);
}
Once set, there is no way to unset view parameters of type 'staticValue'.
I suggest that the __call function check the 'truthiness' of the argument, and set/clear that parameter accordingly.
} elseif ( $this->query_defs[$name]['filter'] == 'staticValue' ) {
- $this->query_parameters[ $this->query_defs[$name]['name'] ] = $this->query_defs[$name]['staticValue'];
+ if (reset($args)) $this->query_parameters[ $this->query_defs[$name]['name'] ] = $this->query_defs[$name]['staticValue'];
+ else unset($this->query_parameters[ $this->query_defs[$name]['name'] ]);
} elseif ( $this->query_defs[$name]['filter'] == 'jsonEncode' ) {
While it seems pretty logical to me, it does have the potential to break existing code: eg a programmer writing "$client->stale=false;" and expecting "stale=ok"
since described here : http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
couchdb 1.1.0 support a query with stale=update_after...
can it be done? cause I read the source code in lib/couchClient.php line 64, there is no update_after option...
sorry if my english bad. i hope you get what i mean
Hi !
First of all, many thanks for your great work :)
I think there is a unintentional mistake (maybe I'm wrong) in couchAdmin.php line 224 :
couchAdmin.php:224: return $client->startkey("org.couchdb.user:")->endkey("org.couchdb.user;")->getAllDocs()->rows;
there is a ';' instead of a ':' in the endkey.
I got this kind of error message :
PHP Fatal error: Uncaught exception 'couchException' with message 'Bad Request - No rows can match your key range, reverse your start_key and end_key or set descending=true (GET /_users/_all_docs {"startkey":""org.couchdb.user:"","endkey":""org.couchdb.user;""})' in /var/www/bkg.com/lib/couchClient.php:1016\nStack trace:\n#0 /var/www/bkg.com/lib/couchClient.php(157): couchException::factory(Array, 'GET', '/_users/_all_do...', Array)\n#1 /var/www/bkg.com/lib/couchClient.php(937): couchClient->_queryAndTest('GET', '/_users/_all_do...', Array, Array, NULL)\n#2 /var/www/bkg.com/lib/couchAdmin.php(224): couchClient->getAllDocs()\n#3 /var/www/bkg.com/cgi-bin/list_all_users.php(43): couchAdmin->getAllUsers()\n#4 {main}\n thrown in /var/www/bkg.com/lib/couchClient.php on line 1016, referer: http://lithium/
Hi! Not sure if this is really about the library, so feel free to close ticket if it's not.
When i'm trying to update a document with updateDoc(), i get the following message:
Fatal error: Uncaught exception 'couchException' with message 'Length Required (PUT [my url]...
I've tried with both Basic API and Full API.
Anyone else have this problem?
Thanks!
I'm using 'PHP On Couch' plugin for accessing couchDB through php. And i don't know how to add multiple attachments to a document
$client = new couchClient($couch_dsn,$couch_db);
$doc = $client->getDoc('meantime');
$res1 = $client->storeAttachment($doc,'files/file1.html','text/html', 'file1.html');
$res2 = $client->storeAttachment($doc,'files/file2.html','text/html', 'file2.html');
Only one attachment is tied to document but not the second?
It is in many cases desirable to catch particular error types - For instance to discriminate between document not found and server failure. I have written improvements to the couchException class that try to identify the failure and construct the proper sub-exception. It is of course, easy to extend to other error types, but these are the only ones I've had to handle so far.
In _queryAndTest, on error:
throw couchException::factory($response, $method, $url, $parameters);
The code that makes it work:
/**
* customized Exception class for CouchDB errors
*
* this class uses : the Exception message to store the HTTP message sent by the server
* the Exception code to store the HTTP status code sent by the server
* and adds a method getBody() to fetch the body sent by the server (if any)
*
*/
class couchException extends Exception {
protected static $code_subtypes = array(404=>'couchNotFoundException', 403=>'couchForbiddenException', 401=>'couchUnauthorizedException', 417=>'couchExpectationException');
protected static $status_subtypes = array('Conflict'=>'couchConflictException');
public static function factory($response, $method, $url, $parameters) {
//var_dump(compact('response', 'method','url','parameters'));
if (is_string($response)) $response = couch::parseRawResponse($response);
if (!$response) return new couchNoResponseException();
if (isset($response['status_code']) and isset(self::$code_subtypes[$response['status_code']]))
return new self::$code_subtypes[$response['status_code']]($response, $method, $url, $parameters);
elseif (isset($response['status_message']) and isset(self::$status_subtypes[$response['status_message']]))
return new self::$status_subtypes[$response['status_message']]($response, $method, $url, $parameters);
else
return new self($response, $method, $url, $parameters);
}
// couchDB response once parsed
protected $couch_response = array();
/**
*class constructor
*
* @param string $raw_response HTTP response from the CouchDB server
*/
function __construct(array $response, $method, $url, $parameters) {
if (is_string($response)) $response = couch::parseRawResponse($response);
$this->couch_response = $response;
if (is_object($this->couch_response['body']) and isset($this->couch_response['body']->reason))
$message = $this->couch_response['status_message'] . ' - ' . $this->couch_response['body']->reason;
else
$message = $this->couch_response['status_message'];
$message.= " ($method $url ".json_encode($parameters).')';
parent::__construct($message, isset($this->couch_response['status_code']) ? $this->couch_response['status_code'] : null);
}
/**
* returns CouchDB server response body (if any)
*
* if the response's "Content-Type" is set to "application/json", the
* body is json_decode()d
*
* @return string|object|null CouchDB server response
*/
function getBody() {
return $this->couch_response['body'];
}
}
class couchNoResponseException extends couchException {
function __construct() {
parent::__construct(array('status_message'=>'No response from server - '));
}
}
class couchNotFoundException extends couchException {}
class couchForbiddenException extends couchException {}
class couchUnauthorizedException extends couchException {}
class couchExpectationException extends couchException {}
class couchConflictException extends couchException {}
I know you can create a doc like so:
$new_doc = new stdClass();
$new_doc->title = "Some content";
And then one by one, add new items to the array like we see above with title
. But if I already have an array that I want to add to the doc stored into let's say $doc_array
, how would I do that?
The parseRawResponse method fails to interpret the status code correctly on bulk set operations above a certain size...
On creating docs in bulk, couchdb will return a header like:
"HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 201 Created\r\n(rest of header)"
parseRawResponse thinks 100 is the code, not 201.
A fix: Added this snippet to line 99 of couch.php
if ( !substr_compare($raw_data, "HTTP/1.1 100 Continue\r\n\r\n", 0, 25) )
{ $raw_data = substr($raw_data, 25); }
When passing \uFFF0 a second encoding pass is performed on startkey / endkey. If there is a correct way to pass these values I would like to know. I need to pass this because I am using utf-8 data and need the full range when getting back my view. To fix it I made a small ugly hack that im sure someone can improve upon easily:
couchClient.php line 170 function __call:
$fixedencode = str_replace('\\\\u', '\\u', json_encode(reset($args)));
$this->query_parameters[ $this->query_defs[$name]['name'] ] = $fixedencode;
This just looks for \uXXXX and removes the encoding or it ends up passing \uXXXX which couch sees as just a slash and some text.
I hope this helps.
I've tried and tried and tried getting composer autoloader support working for PHP-on-Couch but to no avail :-( I'd really love it if this was possible to implement (this is not my strongest side)
Thumbs up on the recent composer support !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.