Рекурсивный акроним словосочетания «PHP: Hypertext Preprocessor»
Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 18028 программистов и 1743 робота. Сейчас ищут 1266 программистов ...
Tutorial
Вернуться к: Manual
Содержание
- Making a Connection
- Getting a Database
- Getting A Collection
- Inserting a Document
- Finding Documents using MongoCollection::findOne
- Adding Multiple Documents
- Counting Documents in A Collection
- Using a Cursor to Get All of the Documents
- Setting Criteria for a Query
- Getting A Set of Documents With a Query
- Creating An Index
Внимание
This extension is deprecated. Instead, the MongoDB extension should be used.
This is the official MongoDB driver for PHP.
Here's a quick code sample that connects, inserts documents, queries for documents, iterates through query results, and disconnects from MongoDB. There are more details on each step in the tutorial below.
<?php
// connect
$m = new MongoClient();
// select a database
$db = $m->comedy;
// select a collection (analogous to a relational database's table)
$collection = $db->cartoons;
// add a record
$document = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
$collection->insert($document);
// add another record, with a different "shape"
$document = array( "title" => "XKCD", "online" => true );
$collection->insert($document);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $document) {
echo $document["title"] . "\n";
}
?>
Результат выполнения данного примера:
Calvin and Hobbes XKCD
Вернуться к: Manual