4、PHP测试分片集群

对数据库test_db2新建两个用户,一个只读用户,一个读写用户

user test_db2

#可读可写

db.createUser(

       {

               user:"ybl",

               pwd:"6055",

               roles:[{"role":"readWrite","db":"test_db2"}]

        }

)

#只读

db.createUser(

       {

               user:"xjl",

               pwd:"6055",

               roles:[{"role":"read","db":"test_db2"}]

       }

)

php安装MongoDB扩展查看此处

try{    $conn=new\MongoClient("mongodb://ybl:[email protected]:20000,127.0.0.144:20000",array("db"=>"test_db2"));

}catch(MongoConnectionException$e){

       echo$e->getMessage();

}

如果认证未通过,则捕获到异常

Failed to connect to: 10.99.121.185:20000: SASL

Authentication failed on database 'test_db': Authentication failed.; Failed to

connect to: ybl:[email protected]:20000: php_network_getaddresses: getaddrinfo

failed: Name or service not known12

你可能感兴趣的:(4、PHP测试分片集群)