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 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿