downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Mongo> <定義済み定数
Last updated: Fri, 13 Nov 2009

view this page in

この例では、データベースへの接続から オブジェクトの挿入、オブジェクトへの問い合わせ、 問い合わせ結果の処理、そして Mongo データベースとの接続の切断までを扱います。

例1 Mongo の例

<?php

include "mongo.php";

// 接続
$m = new Mongo();

// データベースの選択
$db $m->selectDB("comedy");
$collection $db->selectCollection("cartoons");

// 要素の追加
$obj = array( "title" => "Calvin and Hobbes""author" => "Bill Watterson" );
$collection->insert($obj);

// 別の "シェイプ" による別の要素の追加
$obj = array( "title" => "XKCD""online" => true );
$collection->insert($obj);

// コレクション内の全要素の検索
$cursor $collection->find();

// 結果の反復処理
foreach ($cursor as $obj) {
    echo 
$obj["title"] . "\n";
}

// 接続の切断
$m->close();

?>

上の例の出力は、 たとえば以下のようになります。

Calvin and Hobbes
XKCD


add a note add a note User Contributed Notes
There are no user contributed notes for this page.

Mongo> <定義済み定数
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites