dtkwt62022 2018-07-17 15:40
浏览 35

如何将我的php页面连接到远程mongodb服务器?

I need your help. I'm making a project for my thesis and I'm trying to fix this problem for a week without any results. I know that there are a lot of similar topics but I can swear that I didn't find nothing cocern my problem.

I have a web domain on "register.it" where my website has supposed to be. My website need to communicate and handle data from mongo database. So, I have also a remote server (with Ubuntu 16.04) where I install everything correctly (I followed an online guide and tested everything). In fact, locally (I mean, with the mongo shell), there aren't any problem. If I use "systemctl status mongod" it is active. These are other features of the environment:

  • php 7.0.30
  • mongodb 3.4.16
  • mongodb driver 1.5.1
  • mongodb database driver 1.6.16

Of course, I also added the extension in the "php.ini" file and allowed the connection from anywhere to the port 27017.

My simple page php have this code:

$mongo = new MongoClient('mongodb://user_of_db_admin:passwd_of_db_admin@151.236.61.166:27017/admin'); echo "Connection to database successfull."

But it doesn't print anything. If I write only the echo, obviously, it will show the text. And if I write this code instead of the echo:

$dbs = $mongo->listDBs(); print_r($dbs);

the page will show this text "listDbs(); print_r($dbs);". In others questions the users complaining because the page showed an error about the connection mongo function (or at least some error message), but I receive only text or a blank page.

I hope you could help me. If there are others information that you need, tell me and I will update my post.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 NAO机器人的录音程序保存问题
    • ¥15 C#读写EXCEL文件,不同编译
    • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
    • ¥15 扩散模型sd.webui使用时报错“Nonetype”
    • ¥15 stm32流水灯+呼吸灯+外部中断按键
    • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
    • ¥15 NX MCD仿真与博途通讯不了啥情况
    • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
    • ¥15 gradio的web端页面格式不对的问题
    • ¥15 求大家看看Nonce如何配置