WEB开发网
开发学院数据库MySQL 针对PHP开发人员的CouchDB基础知识 阅读

针对PHP开发人员的CouchDB基础知识

 2010-10-06 20:43:22 来源:WEB开发网   
核心提示: 清单 3. 获得数据库信息try { $info = $client->getDatabaseInfos();} catch (Exception $e) { echo "Error:".$e->getMessage()." (errcode=".$e->ge

 清单 3. 获得数据库信息

  
try {
 $info = $client->getDatabaseInfos();
} catch (Exception $e) {
 echo "Error:".$e->getMessage()." (errcode=".$e->getCode().")\n";
 exit(1);
}
print_r($info);

 清单 4. 数据库信息

stdClass Object
(
 [db_name] => songs
 [doc_count] => 2
 [doc_del_count] => 0
 [update_seq] => 2
 [purge_seq] => 0
 [compact_running] =>
 [disk_size] => 8281
 [instance_start_time] => 1266082749089965
 [disk_format_version] => 4
)

 清单 5. 从数据库中检索一首歌

try {
 $doc = $client->getDoc('whatever_you_like');
} catch (Exception $e) {
 if ( $e->code() == 404 ) {
 echo "Document not found\n";
 } else {
 echo "Error: ".$e->getMessage()." (errcode=".$e->getCode().")\n";
 }
 exit(1);
}
print_r($doc);
 


 清单 6. 检索到的歌曲

				
stdClass Object
(
    [_id] => whatever_you_like
    [_rev] => 1-1d915e4c209a2e47e5cf05594f9f951b
    [title] => Whatever You Like
    [artist] => T.I.
    [album] => Paper Trail
)

            

 清单 7. 更新一个文档
				
$doc->genre = 'hip-hop';
$doc->year = 2008;
try {
        $response = $client->storeDoc($doc);
} catch (Exception $e) {
        echo "Error: ".$e->getMessage()." (errcode=".$e->getCode().")\n";
        exit(1);
}
            

 清单 8. 更新后的文档
				
stdClass Object
(
    [_id] => whatever_you_like
    [_rev] => 2-12513a362693b300928aa45f82faed83
    [title] => Whatever You Like
    [artist] => T.I.
    [album] => Paper Trail
    [genre] => hip-hop
    [year] => 2008
)
            

1 2 3 4 5 6  下一页

Tags:针对 PHP 开发

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接