- Improved the Blog model sample
[activemongo.git] / sample / sample.php
blob4b669eda2658b37f2e32b6c37c6ec3d83b5cebb6
1 <?php
2 /*
3 +----------------------------------------------------------------------+
4 | Copyright (c) 2009 The PHP Group |
5 +----------------------------------------------------------------------+
6 | This source file is subject to version 3.0 of the PHP license, |
7 | that is bundled with this package in the file LICENSE, and is |
8 | available through the world-wide-web at the following url: |
9 | http://www.php.net/license/3_0.txt. |
10 | If you did not receive a copy of the PHP license and are unable to |
11 | obtain it through the world-wide-web, please send a note to |
12 | license@php.net so we can mail you a copy immediately. |
13 +----------------------------------------------------------------------+
14 | Authors: Cesar Rodas <crodas@php.net> |
15 +----------------------------------------------------------------------+
17 require "../ActiveMongo.php";
18 require "user.php";
20 ActiveMongo::connect("activemongo_test");
22 /* Create index (and therefore our collection) */
23 $users = new Users;
24 $users->setup();
26 for ($i=0; $i < 500; $i++) {
27 $user = new Users;
28 $user->username = uniqid();
29 $user->password = uniqid();
30 $user->uid = rand(0,10000);
31 $user->karma = rand(0, 20);
32 $user->save(false); /* perform a non-safe but fast save() */
35 /* Simple selection */
36 $users = new Users;
37 $users->uid = 5;
38 foreach ($users->find() as $id=>$u) {
39 var_dump(array('first loop', $id, $u->password));
42 /* Complex selection, it gives you the control
43 * over MongoDB Collection
45 foreach ($users->my_selector() as $id => $user) {
46 var_dump(array($id, $user->uid, $user->password));
49 $users->mapreduce();
51 $users->drop();