PHP操作mongodb没反应 如图,操作没有反应,出现这些东西是什么原因。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // 连接mongodb function conn($dbhost, $dbname, $dbuser, $dbpasswd){ $server = 'mongodb://'.$dbuser.':'.$dbpasswd.'@'.$dbhost.'/'.$dbname; try{ $conn = new MongoClient($server); $db = $conn->selectDB($dbname); } catch (MongoException $e){ throw new ErrorException('Unable to connect to db server. Error:' . $e->getMessage(), 31); } return $db; }// 查询function query($dbconn, $tablename, $limit=10){ $coll = $dbconn->selectCollection($tablename); $cursor = $coll->find(); $cursor = $cursor->limit($limit); $result = array(); foreach($cursor as $v){ $result[] = $v; } return $result; } $db = conn('192.168.0.73','student','root','12345678'); $result = query($db, 'stu'); print_r($result); 试试 楼主你的这个是php7操作mongo吗 查询sql语句 php可以用指针吗??? str_replace的奇怪现象,大家帮帮忙 谁提供点{模板标签}相关资料 [讨论]有经验的PHPER请进 谁知道http://www.limcn.com/bbs/ 这个论坛用的是什么模板? mysql不支持中文全文索引,你在建站中是怎么解决全文搜索的? 关于一个浮动窗口的小问题,谢谢各位高手帮忙! php中文问题? 怎么办才好,关于文件上传的问题,在线等待!!!!! 关于php的访问虚拟目录的url问题 求助各位大神们,php后台怎么实现直接接受前台的JSON对象information,使用js和ajax如何把JSON对象传递给php后台?
// 连接mongodb
function conn($dbhost, $dbname, $dbuser, $dbpasswd){
$server = 'mongodb://'.$dbuser.':'.$dbpasswd.'@'.$dbhost.'/'.$dbname;
try{
$conn = new MongoClient($server);
$db = $conn->selectDB($dbname);
} catch (MongoException $e){
throw new ErrorException('Unable to connect to db server. Error:' . $e->getMessage(), 31);
}
return $db;
}// 查询
function query($dbconn, $tablename, $limit=10){
$coll = $dbconn->selectCollection($tablename);
$cursor = $coll->find();
$cursor = $cursor->limit($limit);
$result = array();
foreach($cursor as $v){
$result[] = $v;
}
return $result;
} $db = conn('192.168.0.73','student','root','12345678');
$result = query($db, 'stu');
print_r($result); 试试