[英]Db Error while connecting with Yii Db settings
我收到以下錯誤。
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',
),
),
),
),
);
我認為您缺少課程:
'db'=>array(
'class'=>'CDbConnection', // specify class
'connectionString' => 'mysql:host=localhost;dbname=mydb',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
我認為mysql服務器未在您的計算機或您使用的服務器上運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.