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 :)

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

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,