php連結mongo資料庫

來源:互聯網
上載者:User
$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);
沒有報錯了

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.