mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
updated manual, added connection section
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@296032 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
42e8f18733
commit
4ae2d3df73
5 changed files with 168 additions and 84 deletions
|
@ -9,7 +9,45 @@
|
|||
<link xlink:href="&url.pecl.package;mongo">&url.pecl.package;mongo</link>.
|
||||
</para>
|
||||
|
||||
<section>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
<link xlink:href="#mongo.installation.nix">Installing on *NIX</link>
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<link xlink:href="#mongo.installation.manual">Manual Installation</link>
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<link xlink:href="#mongo.installation.osx">OS X</link>
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<link xlink:href="#mongo.installation.gentoo">Gentoo</link>
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<link xlink:href="#mongo.installation.fedora">Fedora</link>
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<link xlink:href="#mongo.installation.windows">Installing on Windows</link>
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<link xlink:href="#mongo.installation.thirdparty">Third-Party Installation Instructions</link>
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<section xml:id="mongo.installation.nix">
|
||||
<title>Installing on *NIX</title>
|
||||
|
||||
<para>
|
||||
|
@ -37,7 +75,7 @@ extension=mongo.so
|
|||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.installation.manual">
|
||||
<title>Manual Installation</title>
|
||||
|
||||
<para>For driver developers and people interested in the latest bugfixes, you
|
||||
|
@ -96,7 +134,7 @@ $ sudo make install
|
|||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.installation.osx">
|
||||
<title>OS X</title>
|
||||
|
||||
<para>
|
||||
|
@ -130,7 +168,7 @@ sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo
|
|||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.installation.gentoo">
|
||||
<title>Gentoo</title>
|
||||
<para>On Gentoo using PECL you might get an error that libtool is the wrong
|
||||
version. Compiling from source you'll need to run aclocal and autoconf.
|
||||
|
@ -144,7 +182,7 @@ $ phpize && aclocal && autoconf && ./configure && make && make install
|
|||
(Thanks to <link xlink:href="&url.mongodb.tweet.gentoo;">@riklaunim</link>)
|
||||
</para>
|
||||
</section>
|
||||
<section>
|
||||
<section xml:id="mongo.installation.fedora">
|
||||
<title>Fedora</title>
|
||||
<para>
|
||||
If you don't want to modify php.ini directly, you can create a separate
|
||||
|
@ -162,7 +200,7 @@ extension=mongo.so
|
|||
</section>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.installation.windows">
|
||||
<title>Installing on Windows</title>
|
||||
|
||||
<para>
|
||||
|
@ -239,7 +277,7 @@ extension=php_mongo.dll
|
|||
</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section xml:id="mongo.installation.thirdparty">
|
||||
<title>Third-Party Installation Instructions</title>
|
||||
|
||||
<para>
|
||||
|
|
73
reference/mongo/connecting.xml
Normal file
73
reference/mongo/connecting.xml
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section xml:id="mongo.connecting" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Connecting</title>
|
||||
|
||||
<para>
|
||||
Connecting to MongoDB can be as easy as <literal>new Mongo</literal>, but
|
||||
there are many additional options and configurations. The
|
||||
<function>Mongo::__construct</function> page covers all of the API options,
|
||||
but this page gives some more practical use cases.
|
||||
</para>
|
||||
|
||||
<section>
|
||||
<title>Logging In on Connection</title>
|
||||
<para>
|
||||
If MongoDB is started with the <literal>--auth</literal> option, connections
|
||||
must be authenticated before they are used. You can do this on a
|
||||
per-database level with <function>MongoDB::authenticate</function>:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$m = new Mongo();
|
||||
$db = $m->admin;
|
||||
|
||||
$db->authenticate($username, $password);
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
There is a major disadvantage to this method: if the database connection is
|
||||
dropped and then autoreconnects, the connection will no longer be
|
||||
authenticated.
|
||||
</para>
|
||||
<para>
|
||||
If you use the connection string format described by
|
||||
<function>Mongo::__construct</function>, the database will authenticate the
|
||||
connection as soon as it connects and reauthenticate if the connection is
|
||||
re-esetablished.
|
||||
</para>
|
||||
<para>
|
||||
This is equivalent to the code above, except that reconnections to the
|
||||
database will automatically be authenticated:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$m = new Mongo("mongodb://${username}:${password}@localhost");
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
By default, the driver will authenticate the user against the admin database.
|
||||
To authenticate with a different database, specify the database name after
|
||||
the hosts. This example will log the user into the "blog" database:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$m = new Mongo("mongodb://${username}:${password}@localhost/blog");
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</section>
|
||||
|
||||
</section>
|
|
@ -1,76 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision$ -->
|
||||
|
||||
<section 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
|
||||
|
||||
// connect
|
||||
$m = new Mongo();
|
||||
|
||||
// select a database
|
||||
$db = $m->comedy;
|
||||
$collection = $db->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
|
||||
foreach ($cursor as $obj) {
|
||||
echo $obj["title"] . "\n";
|
||||
}
|
||||
|
||||
// disconnect
|
||||
$m->close();
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.similar;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Calvin and Hobbes
|
||||
XKCD
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</section>
|
||||
|
||||
<!-- 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:"~/.phpdoc/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
|
||||
-->
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
&reference.mongo.configure;
|
||||
&reference.mongo.ini;
|
||||
&reference.mongo.tutorial;
|
||||
&reference.mongo.examples;
|
||||
&reference.mongo.connecting;
|
||||
&reference.mongo.queries;
|
||||
&reference.mongo.updates;
|
||||
&reference.mongo.trouble;
|
||||
|
|
|
@ -401,4 +401,53 @@ $coll->ensureIndex( array( "i" => -1, "j" => 1 ) ); // index on "i" descending,
|
|||
</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
<section>
|
||||
<title>A Quick Example</title>
|
||||
<para>
|
||||
This example connects, inserts objects, queries for objects, iterates through
|
||||
query results, and disconnects from MongoDB.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
// connect
|
||||
$m = new Mongo();
|
||||
|
||||
// select a database
|
||||
$db = $m->comedy;
|
||||
$collection = $db->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
|
||||
foreach ($cursor as $obj) {
|
||||
echo $obj["title"] . "\n";
|
||||
}
|
||||
|
||||
// disconnect
|
||||
$m->close();
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
This would output:
|
||||
</para>
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Calvin and Hobbes
|
||||
XKCD
|
||||
]]>
|
||||
</screen>
|
||||
</section>
|
||||
</section>
|
||||
|
|
Loading…
Reference in a new issue