使用symfony和MAMP时的PDO连接错误 [英] PDO connection error when using symfony and MAMP

查看:124
本文介绍了使用symfony和MAMP时的PDO连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试执行
php symfony doctrine获取PDO错误:insert-sql


我得到的错误:

Getting an PDO error when trying to do php symfony doctrine:insert-sql
The error I get:


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

databases.yml


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

执行 mysql -u root -p jobeet 以root作为密码给我访问,所以没有问题。是的,我运行的mysql是MAMP的。

Doing a mysql -u root -p jobeet with "root" as password gives me access, so no problem there. And yes, the mysql that I run is MAMP's.

感谢任何帮助。

推荐答案

MAMP默认不允许TCP连接。您可以打开它或使用套接字。

MAMP by default doesn't allow TCP connections. You can either turn it on or use sockets.

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

Changing your dsn as @Tom suggests should fix your issues. Weird as it is but using localhost instead of 127.0.0.1 makes that mysql connects through sockets.

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


在Unix上,MySQL程序特别处理主机
名称localhost,以某种方式
可能与您的
期望与其他基于网络的
程序相比有所不同。为了连接到
localhost,MySQL程序尝试使用
Unix套接字文件连接到本地服务器。即使
a --port或-P选项被赋予
,也会发生这种情况,指定端口号。要确保
客户端向本地服务器发送TCP / IP连接
,请使用-host或-h
指定主机名值
127.0.0.1,或本地服务器的IP地址或名称。您也可以
明确指定连接协议
,即使是localhost,也可以使用--protocol = TCP选项

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.

这篇关于使用symfony和MAMP时的PDO连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆