MongoDB的数据类型和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
|
<?php
// test.php
$m=newMongo();
$mark= time();
$x=array(
"id"=>newMongoId(),
"a"=>newMongoDate(),
"b"=>newMongoTimestamp(),
"c"=>newMongoCode('function hello(){}'),
"d"=>newMongoBinData(file_get_contents('test.txt')),
"e"=>newMongoMinKey(),
"f"=>newMongoMaxKey(),
"g"=> 4,
"h"=>newMongoInt32(),
"i"=>newMongoInt64('1234567890123456789'),
"j"=> null,
"k"=> 0.1234567,
"l"=> true,
"m"=>"hello, world",
"n"=>array("foo"=>"bar"),
"mark"=>$mark,
);
$m->test->blog->insert($x);
$result=$m->test->blog->findOne(array('mark'=>$mark));
var_dump($result);
|
输出结果:
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
|
# /usr/local/php5/bin/php test.php
array(17) {
["_id"]=>
object(MongoId)#16 (1) {
["$id"]=>
string(24)"4f8ee09d4efb09782a000001"
}
["id"]=>
object(MongoId)#17 (1) {
["$id"]=>
string(24)"4f8ee09d4efb09782a000000"
}
["a"]=>
object(MongoDate)#18 (2) {
["sec"]=>
int(1334763677)
["usec"]=>
int(51000)
}
["b"]=>
object(MongoTimestamp)#19 (2) {
["sec"]=>
int(1334763677)
["inc"]=>
int(0)
}
["c"]=>
object(MongoCode)#20 (2) {
["code"]=>
string(18)"function hello(){}"
["scope"]=>
array(0) {
}
}
["d"]=>
object(MongoBinData)#21 (2) {
["bin"]=>
string(12) "TEST STRING
"
["type"]=>
int(2)
}
["e"]=>
object(MongoMinKey)#22 (0) {
}
["f"]=>
object(MongoMaxKey)#23 (0) {
}
["g"]=>
int(4)
["h"]=>
int(0)
["i"]=>
float(1.2345678901235E+18)
["j"]=>
NULL
["k"]=>
float(0.1234567)
["l"]=>
bool(true)
["m"]=>
string(12)"hello, world"
["n"]=>
array(1) {
["foo"]=>
string(3)"bar"
}
["mark"]=>
int(1334763677)
}
|
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
|
> x
{
"_id": ObjectId("4f8ee09d4efb09782a000001"),
"id": ObjectId("4f8ee09d4efb09782a000000"),
"a": ISODate("2012-04-18T15:41:17.051Z"),
"b": {
"t": 1334763677000,
"i": 0
},
"c":functioncf__2__f_hello() {
},
"d": undefined,
"e": {
"$minKey": 1
},
"f": {
"$maxKey": 1
},
"g": 4,
"h": 0,
"i": NumberLong("1234567890123456789"),
"j":null,
"k": 0.1234567,
"l":true,
"m":"hello, world",
"n": {
"foo":"bar"
},
"mark": 1334763677
}
|
转自:http://onepiece.me/blog/mongodb-data-types-in-php-driver