Hello,
I’m very new to Couchbase. Previously tried using the C SDK. I managed to figure out how to use it.
But now I’m trying to get it to work with PHP so that I can set up some web service to provide a read and write access to couchbase.
However, I can’t even get past the initial stages of running some sample codes.
<?php
define("COUCHBASE_CONNSTR", "http://127.0.0.1");
define("COUCHBASE_BUCKET", "SaveData");
define("COUCHBASE_PASSWORD", "password");
define("COUCHBASE_VIEW", "player");
define("DOCUMENT_KEY", "10001_RP");
define("INDEX_DISPLAY_LIMIT", 10);
if (extension_loaded('couchbase'))
{
//connecting to the cluster
$cluster = new CouchbaseCluster(COUCHBASE_CONNSTR);
//opening the bucket
$bucket = $cluster->openBucket(COUCHBASE_BUCKET, COUCHBASE_PASSWORD);
$result = $bucket->get(DOCUMENT_KEY);
if ($result == true)
{
$doc = $result->value;
if ($doc)
{
$changed = json_decode($doc, true);
$changedObj = $changed["name"];
echo 'Details:'.$changedObj."\n";
$result = $bucket->replace(DOCUMENT_KEY, $doc);
}
}
$cb = new Couchbase(COUCHBASE_CONNSTR.":8091", "", COUCHBASE_PASSWORD, COUCHBASE_BUCKET);
$query = CouchbaseViewQuery::from(COUCHBASE_BUCKET, COUCHBASE_VIEW)->limit(INDEX_DISPLAY_LIMIT);
}
?>
Up to the part where I try to do a GET with the document key, there’s no problems.
but when I try to run a replace, it says “Fatal error: Call to undefined method CouchbaseBucket::replace()”
when I try to use Couchbase to create a new connection and access it via a view, i get
"Fatal error: Class ‘Couchbase’ not found"
When I try to use CouchbaseViewQuery, it also gives me the same problem.
I’m not sure where I went wrong. but it pretty much looks like a pathing issue or I’m not including something somewhere.
This is how I set up my environment.
- Install XAMPP on my machine (32bit version). My windows is 64 bits though.
- Download the precompiled Libraries (php_couchbase-2.0.0-5.5-zts-vc11-x86.zip) (32bit version)
- Download the precompiled Libraries for couchbase C SDK. (libcouchbase-2.4.3_x86_vc11.zip) (32bit version)
- Copied all the required DLL files to the locations they need to be at (I basically followed the instructions here (http://trondn.blogspot.no/2013/04/couchbase-php-xampp-and-windows.html)
- Start up my Apache Server
- Check phpinfo()
I see this
couchbase
Version 2.0
- and I started testing my php scripts using php.exe.
and I’m stuck.
Please advise… I’m completely lost…
oh please do ignore the logic in the code. I"m just randomly running the commands to make sure it all works before I start developing proper.