2017-09-07 35 views
1

我正在使用php-on-couch庫從couchdb檢索數據 我想基於哪裏檢索條件。我想根據登錄用戶的數據。我的代碼下面檢索一個視圖稱爲帳戶,但我想要檢索,而無需在couchdb上創建視圖。任何幫助,高度讚賞如何動態查詢沙發db

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

有沒有更好的方式來動態地創建檢索就像MySQL的一個看法?

回答

1

使用php-on-couch你可以做到這一點

try { 

    $opts = array("include_docs" => true, "key" => "your user name"); 
    $doc = $client->setQueryParameters($opts)->getView("accounts", "accounts"); 

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

確保你發出的用戶名作爲帳戶的主要查看。 Couch db將在視圖中的所有帳戶中進行搜索,併爲您提供包含您的用戶名的文檔。

emit(doc.username, doc); 

希望它在PHP

使用CouchDB的幫助你休息