【发布时间】:2014-02-15 14:47:06
【问题描述】:
我收到以下错误。
CDbConnection failed to open the DB connection: 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.
这是我的 Db 设置,现在我是 Yii 的新手,所以我不知道是否还有其他需要提及的内容,所以如果有其他内容请告诉我,我会尽快粘贴。
// 这是 yiic 控制台应用程序的配置。 // 任何可写的 CConsoleApplication 属性都可以在这里配置。
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// preloading 'log' component
'preload'=>array('log'),
// application components
'components'=>array(
// 'db'=>array(
// 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
// ),
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=mydb',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
);
【问题讨论】:
-
你的本地主机上安装了 MySQL 吗?它在运行吗? (您发布的文件是在 控制台/命令提示符 中运行 Yii 的配置。Yii Web 应用程序的配置通常在
main.php中。)