我最近开始使用 Zend 框架。 我开始在本地 XAMPP 服务器上进行开发,一切顺利,但是当我上传到我的 1and1 帐户时,我不断收到以下错误:
消息:SQLSTATE[HY000] [2002] 不能
通过以下方式连接到本地 MySQL 服务器
套接字'/var/run/mysqld/mysqld.sock'
(2)
我尝试将 application.ini 文件中的 resources.db.params.unix_socket 行更改为 phpinfo 中提到的不同行,但没有成功。 我发现这里有人回答了
MySQL服务器是否在同一主机上
作为网络应用程序? 如果没有,你
无法使用套接字连接,并且
需要通过 TCP 连接。
我认为我的网络主机就是这种情况。 如何将 ZF 更改为通过 TCP 连接? 我目前正在使用 PDO_MYSQL。
I have recently started using Zend Framework. I started developing on my local XAMPP server which went fine but when I uploaded to my 1and1 account, I keep getting the following error:
Message: SQLSTATE[HY000] [2002] Can't
connect to local MySQL server through
socket '/var/run/mysqld/mysqld.sock'
(2)
I have tried changing the resources.db.params.unix_socket line in my application.ini file to the different ones mentioned in phpinfo but with no success. I found here that someone answered
Is the MySQL server on the same host
as the web application? If not, you
can't use a socket connection, and
will need to connect via TCP.
I think that is the case with my web host. How can I change ZF to connect via TCP instead? I am currently using PDO_MYSQL.
发布评论
评论(3)
连接 MySQL 的方式取决于传递给 mysql_connect() 的参数。 如果你向它传递一个文件路径,即。
/var/run/mysqld/mysqld.sock
,它将尝试套接字连接。 如果您向其传递主机名,它将尝试建立 TCP 连接。您需要找到 mysql 服务器的主机名(或 IP),然后像这样连接到它:
mysql_connect('127.0.0.1:3306',$username,$password);
ZF 的赔率,您只需在存储数据库设置的配置文件中指定此项,或者在使用
host
设置连接到数据库时指定:编辑:如果您正在将正确的主机名/端口作为主机参数传递给 mysql_connect() 并获取此消息,那么很可能是服务器配置问题。
尝试在 php.ini 中或使用 设置>ini_set()
你必须找出套接字文件在哪里。 通常它是“/var/lib/mysql/mysql.sock”,但我认为它依赖于系统。
How you connect to MySQL depends on the parameters you pass to mysql_connect(). If you pass it a file path, ie.
/var/run/mysqld/mysqld.sock
, it's going to attempt a socket connection. If you pass it a hostname, it will attempt a TCP connection.You need to find the hostname (or IP) of the mysql server, and connect to it like this:
mysql_connect('127.0.0.1:3306',$username,$password);
Odds are for ZF, you can just specify this in the configuration file where you store your database settings, or when you connect to the database using the
host
setting:Edit: If you are passing a proper hostname/port as the host parameter to
mysql_connect()
and getting this message, then it is most likely a server configuration issue.Try adjusting the
mysql.default_socket
setting, either in php.ini or at the top of your application code using ini_set()You'll have to figure out where the socket file is. Often it's '/var/lib/mysql/mysql.sock', but I think it's system dependent.
我已将行:
按原样保留在我的index.php中,但已将 public/.htaccess 更改为
看起来 .htaccess 未被读取。 我将 index.php 中的 else 语句更改为“生产”以使用生产数据库设置,并且它有效。 相当令人沮丧。 我想知道为什么没有读取环境变量。 感谢您的帮助。
I had left the line:
in my index.php as is but had changed public/.htaccess to
It looks like the .htaccess was not being read. I changed the else statement in index.php to 'production' to use the production database settings and it worked. Quite frustrating. I wonder why the environment variable was not being read. Thanks for your help.
Zend Framework 在 db params
unix_socket
中有选项,只需使用它Zend Framework has option in db params
unix_socket
, simply use it