Repository navigation
Expand file tree
/
Copy pathpopulate_db.php
More file actions
107 lines (86 loc) · 3.43 KB
/
Copy pathpopulate_db.php
File metadata and controls
107 lines (86 loc) · 3.43 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
// connect
$m = new MongoClient();
// select a database
$db = $m->shop;
// Drop the database
$response = $db->drop();
//print_r($response);
// select a collection (analogous to a relational database's table)
$collection = $db->orders;
// add records
$obj = array( "id"=>"1234","name"=>"Russell","item"=>"ManCity Jersey","quantity"=>"2");
$collection->insert($obj);
$obj = array( "id"=>"42","name"=>"Adrien","item"=>"Fuzzy pink towel","quantity"=>"1");
$collection->insert($obj);
$obj = array( "id"=>"99","name"=>"Justin","item"=>"Bird supplies","quantity"=>"4");
$collection->insert($obj);
$obj = array( "id"=>"1","name"=>"Robin","item"=>"Music gift cards","quantity"=>"100");
$collection->insert($obj);
$obj = array( "id"=>"1001","name"=>"Moses","item"=>"Miami Heat tickets","quantity"=>"1000");
$collection->insert($obj);
$obj = array( "id"=>"66","name"=>"Rick","item"=>"Black hoodie","quantity"=>"1");
$collection->insert($obj);
$obj = array( "id"=>"0","name"=>"Nobody","item"=>"Nothing","quantity"=>"0");
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $obj) {
echo $obj["name"] . "<br>";
}
// select a database
$db = $m->customers;
// Drop the database
$response = $db->drop();
//print_r($response);
// select a collection (analogous to a relational database's table)
$collection = $db->paymentinfo;
$obj = array( "name"=>"Russell","id"=>"1000","cc"=>"0000000000000000","cvv2"=>"0000");
$collection->insert($obj);
$obj = array( "name"=>"Adrien","id"=>"42","cc"=>"5555123456789999","cvv2"=>"1234");
$collection->insert($obj);
$obj = array( "name"=>"Justin","id"=>"99","cc"=>"5555123456780000","cvv2"=>"4321");
$collection->insert($obj);
$obj = array( "name"=>"Robin","id"=>"1","cc"=>"3333444455556666","cvv2"=>"2222");
$collection->insert($obj);
$obj = array( "name"=>"Moses","id"=>"2","cc"=>"4444555566667777","cvv2"=>"3333");
$collection->insert($obj);
$obj = array( "name"=>"Rick","id"=>"3","cc"=>"5555666677778888","cvv2"=>"5678");
$collection->insert($obj);
$obj = array( "name"=>"Nobody","id"=>"0","cc"=>"4500987654321555","cvv2"=>"9999");
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $obj) {
echo $obj["cc"] . "<br>";
}
// select a database
$db = $m->appUserData;
// Drop the database
$response = $db->drop();
//print_r($response);
// select a collection (analogous to a relational database's table)
$collection = $db->users;
$obj = array( "name"=>"Russell","username"=>"tcstoolHax0r","email"=>"nosqlmap@sec642.org");
$collection->insert($obj);
$obj = array( "name"=>"Adrien","username"=>"adrien","email"=>"adrien@sec642.org");
$collection->insert($obj);
$obj = array( "name"=>"Justin","username"=>"justin","email"=>"justin@sec642.org");
$collection->insert($obj);
$obj = array( "name"=>"Robin","username"=>"digininja","email"=>"digininja@sec642.org");
$collection->insert($obj);
$obj = array( "name"=>"Moses","username"=>"adrien","email"=>"moses@sec642.org");
$collection->insert($obj);
$obj = array( "name"=>"Rick","username"=>"rick","email"=>"rick@sec642.org");
$collection->insert($obj);
$obj = array( "name"=>"Nobody","username"=>"administrator","email"=>"root@sec642.org");
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $obj) {
echo $obj["email"] . "<br>";
}
?>