MySQL 带有消息“SQLSTATE[HY000] [2002] zend 框架的“PDOException”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9682464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:29:48  来源:igfitidea点击:

'PDOException' with message 'SQLSTATE[HY000] [2002] zend framework

mysqlzend-frameworkpdozend-db

提问by Edward Maya

Any one plz tell me why i am getting this error ?? firstly my internet connection was good today its not good so i am getting this error.how can i fix this any idea plz??

任何人请告诉我为什么我收到这个错误?首先,我今天的互联网连接很好,但不是很好,所以我收到了这个错误。请问我该如何解决这个问题?

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] A 
connection attempt failed because the connected party did not properly respond after a 

period of time, or established connection failed because connected host has failed to
respond. ' in D:\SVN 
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php:129 

Stack trace: #0 D:\SVN     
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php(129):  
PDO->__construct('mysql:host=192....', 'root', 'root', Array) #1 D:\SVN   
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Mysql.php(109): 
Zend_Db_Adapter_Pdo_Abstract->_connect() #2 D:\SVN  
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Abstract.php(860):  
Zend_Db_Adapter_Pdo_Mysql->_connect() #3 D:\SVN  
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Abstract.php(930):  
Zend_Db_Adapter_Abstract->quote('testing', NULL) #4 D:\SVN 
data\WebClient_PHP\trunk\p\library\Zend\Auth\Adapter\DbTable.php(449): Zen 
in D:\SVN 
data\WebClient_PHP\trunk\p\library\Zend\Db\Adapter\Pdo\Abstract.php on line 
144

this is my config.ini

这是我的 config.ini

[general]
db.adapter = PDO_MYSQL
db.params.host = 192.168.0.233
db.params.username = root
db.params.password = my_password
db.params.dbname = "mydatabasename"

some code from my index.php

我的 index.php 中的一些代码

$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');
$DB = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($DB);

回答by Fawad Ghafoor

it seems that your code this portion is not working

看来你的代码这部分不起作用

[general]
 db.adapter = PDO_MYSQL
 db.params.host = 192.168.0.233
 db.params.username = root
 db.params.password = my_password
 db.params.dbname = "mydatabasename"

either the IP is not correct if so go to cmd in windows and type ipconfig you will get your correct ip paste it here OR just simply write

如果 IP 不正确,请在 Windows 中转到 cmd 并键入 ipconfig,您将获得正确的 ip 将其粘贴到此处,或者只是简单地写

 db.params.host = localhost

if and only if you are using locally may be it works.

当且仅当您在本地使用时它才有效。

回答by Frederick G. Sandalo

for the hostname/host try to use your credentials found in the Zend Server -> PHP Cloud tab -> Overview page -> User Parameters tab... then make the "host" part in the credentials like this:

对于主机名/主机,尝试使用在 Zend Server -> PHP Cloud 选项卡 -> 概览页面 -> 用户参数选项卡中找到的凭据...然后在凭据中添加“主机”部分,如下所示:

[general]
 db.adapter = PDO_MYSQL
 db.params.host = CONTAINERNAME-db.my.phpcloud.com
 db.params.username = ZEND_DB_USERNAME
 db.params.password = ZEND_DB_USERNAME
 db.params.dbname = ZEND_DB_DBNAME

回答by arraintxo

Did you check your mysql database is up?

你检查你的mysql数据库了吗?

If you are sure it is, check that your adapters configuration is ok, maybe the host parameter is not properly configured.

如果您确定是,请检查您的适配器配置是否正常,可能是主机参数配置不正确。