新手求问:
如题,php mongodb扩展装好了。
$m = new MongoClient();//默认连接本地localhost
$db = $m->mlab;
$collection = $db->whois;
这样是没问题的。问题出在远程连接别的机器上的数据库,代码如下:
try{
$m = new MongoClient("10.100.0.159:27017");
$db = $m->smaap;
$db-> authenticate("xxxxx","xxxxx");//密码和用户名
}
catch (Exception $e){
echo $e->getMessage();
exit();
}
try{
$collection = $db->ott_video_dns;
$cursor = $collection->find();
}
catch (Exception $e){
echo $e->getMessage();
exit();
}
try{
foreach ($cursor as $id => $value) {
echo "$id: "; var_dump($value); echo "
";
}
}
catch (Exception $e){
echo $e->getMessage();
exit();
}
这样会报错:
10.100.0.159:27017: not authorized for query on smaap.ott_video_dns
但是用同样用户名和密码用python脚本去跑,能访问数据库,也没问题。本机和数据库所在的机器在同一个网段,用studio 3T也能访问。
求大神帮忙看一下,问题出在什么地方?