forked from syahman/App4Pesima
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestmongo.php
53 lines (40 loc) · 1.26 KB
/
testmongo.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
45
46
47
48
49
50
51
52
53
<?php
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
$username = $mongo_config["username"];
$password = $mongo_config["password"];
$hostname = $mongo_config["hostname"];
$port = $mongo_config["port"];
$db = $mongo_config["db"];
$name = $mongo_config["name"];
$connect = "mongodb://${username}:${password}@${hostname}:${port}/${db}";
try{
$m = new Mongo($connect);
$db = $m->selectDB($db);
$coll = $db->selectCollection('peserta');
} catch(MongoConnectionException $e) {
//handle connection error
die($e->getMessage());
}
echo "insert " ;
$peserta = array(
'nama'=>"fsdfsdf",
'gred'=>"fsdfsdf",
'jabatan'=>"fsdfsdf",
'emel'=>"fsdfsdf",
'peranan'=>"fsdfsdf",
'alahan'=>"fsdfsdf",
'ahli'=>"fsdfsdf"
);
$collection->insert( $peserta );
$cursor = $collection->find();
while ($cursor->hasNext()): $obj = $cursor->getNext();
echo $obj["nama"] . "<br/>";
echo $obj["gred"] . "<br/>";
echo $obj["jabatan"] . "<br/>";
echo $obj["emel"] . "<br/>";
echo $obj["peranan"] . "<br/>";
echo $obj["ahli"] . "<br/>";
echo $obj["alahan"] . "<br/>";
endwhile;
?>