<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Getting A Collection</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongo.tutorial.selectdb.html">Getting a Database</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongo.tutorial.insert.html">Inserting a Document</a></div> <div class="up"><a href="mongo.tutorial.html">Tutorial</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongo.tutorial.collection" class="section"> <h2 class="title">Getting A Collection</h2> <p class="para"> Getting a collection has the same syntax as getting a database: </p> <div class="example" id="mongo.tutorial.collection-example"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$connection </span><span style="color: #007700">= new </span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #0000BB">$connection</span><span style="color: #007700">-></span><span style="color: #0000BB">baz</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// select a collection:<br /></span><span style="color: #0000BB">$collection </span><span style="color: #007700">= </span><span style="color: #0000BB">$db</span><span style="color: #007700">-></span><span style="color: #0000BB">foobar</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// or, directly selecting a database and collection:<br /></span><span style="color: #0000BB">$collection </span><span style="color: #007700">= </span><span style="color: #0000BB">$connection</span><span style="color: #007700">-></span><span style="color: #0000BB">baz</span><span style="color: #007700">-></span><span style="color: #0000BB">foobar</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <p class="para"> A collection is analogous to a table (if you are familiar with relational databases). </p> <div class="section" id="mongo.tutorial.collection.seealso"> <h2 class="title">See Also</h2> <p class="para"> The API documentation on the <a href="class.mongocollection.html" class="classname">MongoCollection</a> class contains more information about collection objects. </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongo.tutorial.selectdb.html">Getting a Database</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongo.tutorial.insert.html">Inserting a Document</a></div> <div class="up"><a href="mongo.tutorial.html">Tutorial</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>