2015-06-19 77 views
1

我正在使用Linux(Ubuntu 15.04)進行Web項目。不知何故,我設法安裝mongodb。我創建了一個用戶,我可以通過終端連接到數據庫。PHP MongoDB身份驗證失敗

但是,當我試圖通過PHP腳本連接到數據庫它給這個錯誤:

Failed to connect to: 127.0.0.1:27017: Authentication failed on database 'user1' with username 'user1': auth failed 

蒙戈驅動程序版本是1.5.7。 MongoDB的版本是3.0.4

此外,當我通過終端連接到數據庫,它給了我這些警告:

MongoDB shell version: 3.0.4 
connecting to: test 
Server has startup warnings: 
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] 
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] **  We suggest setting it to 'never' 
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] 
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] **  We suggest setting it to 'never' 
2015-06-19T18:08:20.354+0300 I CONTROL [initandlisten] 

但它接受db.auth(用戶名,密碼),併成功AUTHS。我可以使用數據庫。但PHP不會連接到數據庫。

請幫忙。我試圖找到解決方案,但每個人都說不同的東西,沒有解決方案。我花了幾個小時才讓它在linux下工作。我討厭Linux,如果找不到解決方案,我會回到Windows。

+1

檢查[這裏](http://stackoverflow.com/questions/29792674/cant-authenticate-on-mongodb-with-php) – Moppo

+1

謝謝@Moppo。我會從幸福中哭泣。謝謝 – zarax

回答

0

Moppo的回答解決了這個問題:

Problem solved: apparenty it was caused by a problem/bug in the PHP mongo driver version 1.4.

I've upgraded the driver to version 1.6 with:

pecl upgrade mongo

and now the authentication works.

感謝