锟斤拷锟� MongoDB 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷时使锟斤拷锟斤拷 --auth 锟斤拷 --keyFile 锟斤拷锟斤拷锟斤拷锟斤拷捅锟斤拷锟斤拷诮锟斤拷锟斤拷魏尾锟斤拷锟角帮拷锟斤拷锟斤拷锟街わ拷锟� 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟绞憋拷锟斤拷锟斤拷锟街わ拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟斤拷锟街革拷锟斤拷没锟斤拷锟斤拷锟斤拷耄拷锟斤拷锟斤拷锟� MongoClient::__construct() 锟斤拷锟届函锟斤拷锟斤拷指锟斤拷 "username" 锟斤拷 "password"锟斤拷
Example #1 锟斤拷锟�"admin"锟斤拷锟捷匡拷锟斤拷锟街�
<?php
// Specifying the username and password in the connection URI (preferred)
$m = new MongoClient("mongodb://${username}:${password}@localhost");
// Specifying the username and password via the options array (alternative)
$m = new MongoClient("mongodb://localhost", array("username" => $username, "password" => $password));
?>
默锟斤拷状态锟铰o拷锟斤拷锟斤拷锟斤拷锟斤拷锟� admin 锟斤拷锟捷匡拷锟斤拷锟斤拷锟街わ拷锟斤拷锟街ひ诧拷锟斤拷远锟斤拷锟斤拷锟斤拷锟斤拷菘锟斤拷锟叫★拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷指锟斤拷锟斤拷锟捷匡拷锟斤拷锟斤拷锟斤拷锟斤拷 MongoClient::__construct() 锟斤拷锟届函锟斤拷锟斤拷指锟斤拷 "db"锟斤拷
Example #2 锟斤拷锟揭伙拷锟斤拷锟斤拷菘锟斤拷锟斤拷证
<?php
// Specifying the authentication database in the connection URI (preferred)
$m = new MongoClient("mongodb://${username}:${password}@localhost/myDatabase");
// Specifying the authentication database via the options array (alternative)
$m = new MongoClient("mongodb://${username}:${password}@localhost", array("db" => "myDatabase"));
?>
锟斤拷锟斤拷锟斤拷锟斤拷卸希锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷鲁锟斤拷锟斤拷锟斤拷硬锟斤拷锟斤拷远锟斤拷锟斤拷锟斤拷锟街わ拷锟�