php-doc-en/reference/mongo/examples.xml
Philip Olson bcbd2e8b37 Whitespace
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@276454 c90b9560-bf6c-de11-be94-00142212c4b1
2009-02-25 22:33:54 +00:00

79 lines
1.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.3 $ -->
<chapter xml:id="mongo.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<para>
This example shows how to connect,
insert objects, query for objects, iterate through
query results, and disconnect from a Mongo database.
</para>
<example>
<title>Mongo Example</title>
<programlisting role="php">
<![CDATA[
<?php
include "mongo.php";
// connect
$m = new Mongo();
// select a database
$db = $m->selectDatabase("comedy");
$collection = $db->selectCollection("cartoons");
// add an element
$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
$collection->insert($obj);
// add another element, with a different "shape"
$obj = array( "title" => "XKCD", "online" => true );
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
while( $cursor->hasNext() ) {
$c = $cursor->next();
echo $c["title"] . "\n";
}
// disconnect
$m->close();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Calvin and Hobbes
XKCD
]]>
</screen>
</example>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->