Home > Backend Development > PHP Tutorial > PHP连接mongodb 数据库问题

PHP连接mongodb 数据库问题

WBOY
Release: 2016-06-20 12:42:42
Original
970 people have browsed it

求教,我用PHP连接芒果数据库,能连接上也能创建数据库,就是无法插入数据。芒果数据库用SHELL客户端操作一切正常。以下是测试代码

<?php$doc = array(		"name" => "MongoDB",		"type" => "database",		"count" => 1,		"info" => (object)array( "x" => 203, "y" => 102),		"versions" => array("0.9.7", "0.9.8", "0.9.9"));$connection = new MongoClient();$collection = $connection->mydb->tbname;$collection->insert( $doc );?>
Copy after login

这个是运行后在数据库查询到的,mydb 已经创建成功,但是数据为空。

困扰我几天了。不知道哪儿出了问题,请各位帮忙。
如果这里说不清楚可以加我QQ 11-50-96-770


回复讨论(解决方案)

db.mydb.find()你句不对。
db. .find()你写成库的名字了。
应用用show collections 查看集合
然后执行这句db.你查看到集合.find()

大神请受我一拜。

困扰我几天了,原来是我数据库资料没看完整。 大神你加我QQ 我必须发个红包给你

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template