forked from rahbirul/PHP_MongoDB_Packt_Book_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_users.php
44 lines (37 loc) · 1.51 KB
/
create_users.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require('dbconnection.php');
$mongo = DBConnection::instantiate();
$collection = $mongo->getCollection('users');
$users = array(
array(
'name' => 'Luke Skywalker',
'username' => 'jedimaster23',
'password' => md5('usetheforce'),
'birthday' => new MongoDate(strtotime('1971-09-29 00:00:00')),
'address' => array('town' => 'Mos Eisley', 'planet' => 'Tatooine')
),
array(
'name' => 'Leia Organa',
'username' => 'princessleia',
'password' => md5('eviltween'),
'birthday' => new MongoDate(strtotime('1976-10-21 00:00:00')),
'address' => array('town' => 'Aldera', 'planet' => 'Alderaan')
),
array(
'name' => 'Chewbacca',
'username' => 'chewiethegreat',
'password' => md5('loudgrowl'),
'birthday' => new MongoDate(strtotime('1974-05-19 00:00:00')),
'address' => array('town' => 'Kachiro', 'planet' => 'Kashyyk')
)
);
foreach($users as $user)
{
try{
$collection->insert($user);
} catch (MongoCursorException $e)
{
die($e->getMessage());
}
}
echo 'Users created successfully';