dpicx06888 2014-12-08 15:48
浏览 28
已采纳

PDO没有连接到远程服务器? [关闭]

When I use mysql_connect('remote_server', 'user', 'pass') it works fine but when I try the following:

$db = new PDO('mysql:dbname=dbname;mysql:host=remote_server', 'user', 'pass');

It doesn't work. I had mysql-client installed on the web server initially. When trying the PDO connection I was receiving this error:

Connection Failed: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

So I installed mysql-server and got the following error instead:

Connection Failed: SQLSTATE[28000] [1045] Access denied for user 'user'@'localhost' (using password: YES)

I'm assuming this is because PDO is trying to connect to the local mysql server instead of the remote server. I tried using the local credentials and it connected but this is obviously not what I want. How do I get a connection to the remote server using a PDO connection to a SQL database? Why is it trying to use user@localhost when I specified a remote server in the DSN?

  • 写回答

1条回答 默认 最新

  • dongleiqiao4906 2014-12-08 16:08
    关注

    Posted on behalf of the OP:

    Can't believe I didn't catch the error in the DSN. Fixed :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改