-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetUserInfo_old.php
51 lines (46 loc) · 1.57 KB
/
getUserInfo_old.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
<?php
//get content success then save to mongoDB
//conect mongoDB
try{
$oldUser = array();
$skinId = intval(urldecode($_REQUEST["skinId"]));
// //working on windhow
$m = new MongoClient("mongodb://45.33.124.160");
$db = $m->selectDB('Dino');
$collection = new MongoCollection($db, 'equipment');
$cursor = $collection->find(array('skinId' => $skinId));
if($cursor->count() == 0){
//không có
$jsonstring = json_encode($oldUser);
echo $jsonstring;
}else{
//update info
foreach($cursor as $doc){
$oldUser = $doc;
break;
}
$jsonstring = json_encode($oldUser);
echo $jsonstring;
}
// //working on ubuntu
// $mng = new MongoDB\Driver\Manager("mongodb://45.33.124.160");
// $filter = ['skinId' => $skinId ];
// //insert or update
// $bulk = new MongoDB\Driver\BulkWrite;
// $query = new MongoDB\Driver\Query($filter);
// $res = $mng->executeQuery("cso.equipment", $query);
// $cursor = current($res->toArray());
// if($cursor){
// //update
// $jsonstring = json_encode($cursor);
// echo $jsonstring;
// }else{
// //không có
// $jsonstring = json_encode($oldUser);
// echo $jsonstring;
// }
}catch(\Exceptions $e){
$jsonstring = json_encode($e);
echo $jsonstring;
}
?>