1.首先通过此链接http://cloud.github.com/downloads/juranki/couchdb/setup-couchdb-1.1.0acff79d0-git.exe下载windows的安装包
2.下载完成双击运行安装,即可
3.在到开始菜单中 Apache CouchDB-》Start CouchDB ,开启数据库
4.可以使用下列php代码进行连接和数据操作测试。
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<?php
set_time_limit(0);
class CouchSimple {
function CouchSimple($options) {
foreach($options AS $key => $value) {
$this->$key = $value;
}
}
function send($method, $url, $post_data = NULL) {
$s = fsockopen($this->host, $this->port, $errno, $errstr);
if(!$s) {
echo "$errno: $errstr\n";
return false;
}
$request = "$method $url HTTP/1.0\r\nHost: $this->host\r\n";
if ($this->user) {
$request .= "Authorization: Basic ".base64_encode("$this->user:$this->pass")."\r\n";
$request .= "\r\n";
}
if($post_data) {
$request .= "Content-Length: ".strlen($post_data)."\r\n\r\n";
$request .= "$post_data\r\n";
}
else {
$request .= "\r\n";
}
fwrite($s, $request);
$response = "";
while(!feof($s)) {
$response .= fgets($s);
}
list($this->headers, $this->body) = explode("\r\n\r\n", $response);
return $this->body;
}
}
$pagestartime=microtime();
$options['host'] = "localhost";
$options['port'] = 5984;
// See if we can make a connection
$couch = new CouchSimple($options);
$resp = $couch->send("GET", "/");
var_dump($resp);
echo "<br/>";
// Get a list of all databases in CouchDb
$resp = $couch->send("GET", "/_all_dbs");
var_dump($resp);
echo "<br/>";
// Create a new database "test"
$resp = $couch->send("PUT", "/test");
var_dump($resp);
echo "<br/>";
// Get a list of all databases in CouchDb
$resp = $couch->send("GET", "/_all_dbs");
var_dump($resp);
echo "<br/>";
// Get all documents in that database
$resp = $couch->send("GET", "/test/_all_docs");
var_dump($resp);
echo "<br/>";
for($i=0;$i<1000;$i++){
// Create a new document in the database test with the id 123 and some data
$resp = $couch->send("PUT", "/test/".$i, '{"id":"'.$i.'","data":"data_'.$i.'"}');
var_dump($resp);
echo "<br/>";
}
// Get all documents in test again, seing doc 123 there
$resp = $couch->send("GET", "/test/_all_docs");
var_dump($resp);
echo "<br/>";
// Get back document with the id 123
$resp = $couch->send("GET", "/test/888");
var_dump($resp);
echo "<br/>";
// Delete our "test" database
$resp = $couch->send("DELETE", "/test/");
var_dump($resp);
echo "<br/>";
$pageendtime = microtime();
$starttime = explode(" ",$pagestartime);
$endtime = explode(" ",$pageendtime);
$totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$timecost = sprintf("%s",$totaltime);
echo "页面运行时间: $timecost 秒";
?>