加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 使用symfony和MAMP时的PDO连接错误

发布时间:2020-12-13 13:39:34 所属栏目:PHP教程 来源:网络整理
导读:尝试做PDO时发生错误 php symfony doctrine:insert-sql 我得到的错误: Warning: PDO::__construct(): [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306) in /Users/johannes/Programmering/PHP/htdocs/symfony/sfprojects/lib/vend
尝试做PDO时发生错误
php symfony doctrine:insert-sql

我得到的错误:

Warning: PDO::__construct(): [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306) in /Users/johannes/Programmering/PHP/htdocs/symfony/sfprojects/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 470

databases.yml里

    all:
    doctrine:
    class: sfDoctrineDatabase
    param:
      dsn: mysql:host=127.0.0.1;dbname=jobeet;
      username: root
      password: root

使用“root”作为密码进行mysql -u root -p jobeet可以访问,所以没有问题.是的,我运行的mysql是MAMP的.

感谢任何帮助.

默认情况下,MAMP不允许TCP连接.您可以打开它或使用套接字.

将dsn更改为@Tom建议您解决问题.奇怪的是,但使用localhost而不是127.0.0.1使mysql通过套接字连接.

http://dev.mysql.com/doc/refman/5.0/en/connecting.html:

On Unix,MySQL programs treat the host name localhost specially,in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost,MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a –port or -P option is given to specify a port number. To ensure that the client makes a TCP/IP connection to the local server,use –host or -h to specify a host name value of 127.0.0.1,or the IP address or name of the local server. You can also specify the connection protocol explicitly,even for localhost,by using the –protocol=TCP option.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读