开发者

php mongodb findOne return as object?

开发者 https://www.devze.com 2022-12-31 01:42 出处:网络
is it possible to return findOne result as object ..or it always 开发者_StackOverflow中文版return an array?

is it possible to return findOne result as object ..or it always 开发者_StackOverflow中文版return an array?

i found something about mongo.objects = 1 adding to php.ini ..but did not work for me.

can some one tell me more about this?


I see no mentioning of the MongoDB PHP driver returning objects in either the API documentation or the tutorial. This is not really surprising as the official drivers stay close to the native bson document type used to represent documents.

There are however plenty of extra libraries that provide such mapping. Looking at the PHP Language Center page at mongodb.org, for example, I see a few libraries that provide direct object mapping, such as simplemongodb or mongodb-php-odm. They use their own API, so maybe just writing a simple conversion function from an array to an object instance yourself is more suited for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号