Home > Backend Development > PHP Tutorial > php链接mongo数据库

php链接mongo数据库

WBOY
Release: 2016-06-23 13:31:48
Original
1299 people have browsed it

$conn = new Mongo("mongodb://admin:admin@localhost:27017/local"); ///这个就是第11行

这么写完之后报错

( ! ) Deprecated: main(): The Mongo class is deprecated, please use the MongoClient class in D:\bzyweb\test2\conn.php on line 11
Call Stack
# Time Memory Function Location
1 0.0010 238592 {main}( ) ..\conn.php:0

( ! ) Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: Authentication failed on database 'local' with username 'admin': auth fails' in D:\bzyweb\test2\conn.php on line 11
( ! ) MongoConnectionException: Failed to connect to: localhost:27017: Authentication failed on database 'local' with username 'admin': auth fails in D:\bzyweb\test2\conn.php on line 11
Call Stack
# Time Memory Function Location
1 0.0010 238592 {main}( ) ..\conn.php:0
2 0.0010 239720 __construct ( ) ..\conn.php:11


回复讨论(解决方案)

Deprecated: main(): The Mongo class is deprecated, please use the MongoClient class 
反对:main():Mongo类是过时的,请使用mongoclient类

echo "mongo contact:
";
//$DB = new PDO("mongodb:host=localhost;port=27017;dbname=aaa","admin","admin");
$conn = new MongoClient("mongodb://admin:admin@localhost2:27017/local");
?>

错误提示
mongo contact:

( ! ) Fatal error: Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): ' in D:\bzyweb\test2\conn.php on line 4
( ! ) MongoConnectionException: MongoClient::__construct(): in D:\bzyweb\test2\conn.php on line 4
Call Stack
# Time Memory Function Location
1 0.0000 240416 {main}( ) ..\conn.php:0
2 0.0000 240672 __construct ( ) ..\conn.php:4

你的下图是什么?mongo 管理器?
你看看他是怎么写的

下图是一个mongoweb的管理地址,我看了好多写法,好像链接都是那么写的,不清楚为什么我的出错了,所以贴出来数据库的结构,我想这样能表述的更清晰一点

$dsn="mongodb://localhost:27017/admin:admin/aaa";
$m=new MongoClient($dsn);
没有报错了

Related labels:
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