2014-10-09 63 views
-3

進入DB配置爲安裝訪問被拒絕的用戶 '根' @ '本地主機'(使用密碼:否)YII

錯誤500 的mysql_connect之後接收錯誤()[function.mysql-連接]:訪問被拒絕的用戶 '根' @ 'localhost' 的(使用密碼:NO)

Db的配置文件(默認)

(
return array (
    'connectionString' => 'mysql:host=localhost;dbname=sarish', 
    'emulatePrepare' => true, 
    'username' => 'sarish', 
    'password' => '[email protected]', 
    'charset' => 'utf8', 
); 

好心幫我

這是安裝控制器代碼

<?php 

/** * 權利安裝控制器類文件。

*/ 類InstallController擴展RController { /** * @property RAuthorizer */ 私人$ _authorizer; /** * @property RInstaller */ private $ _installer;

/** 
* Initializes the controller. 
*/ 
public function init() 
{ 
    if($this->module->install!==true) 
     $this->redirect(Yii::app()->homeUrl); 

    $this->_authorizer = $this->module->getAuthorizer(); 
    $this->_installer = $this->module->getInstaller(); 
    $this->layout = $this->module->layout; 
    $this->defaultAction = 'run'; 

    // Register the scripts. 
    $this->module->registerScripts(); 
} 

/** 
* @return array action filters 
*/ 
public function filters() 
{ 
    // Use access control when installed. 
    return $this->_installer->installed===true ? array('accessControl') : array(); 
} 

/** 
* Specifies the access control rules. 
* This method is used by the 'accessControl' filter. 
* @return array access control rules 
*/ 
public function accessRules() 
{ 
    return array(
     array('allow', // Allow superusers to access Rights 
      'actions'=>array(
       'confirm', 
       'run', 
       'error', 
       'ready', 
      ), 
      'users'=>$this->_authorizer->getSuperusers(), 
     ), 
     array('deny', // Deny all users 
      'users'=>array('*'), 
     ), 
    ); 
} 

/** 
* Displays the confirm overwrite page. 
*/ 
public function actionConfirm() 
{ 
    $this->render('confirm'); 
} 

/** 
* Installs the module. 
* @throws CHttpException if the user is not logged in. 
*/ 
public function actionRun() 
{ 
    // Make sure the user is not a guest. 
    if(Yii::app()->user->isGuest===false) 
    { 
     // Make sure that the module is not already installed. 
     if(isset($_GET['confirm'])===true || $this->_installer->installed===false) 
     { 
      // Run the installer and check for an error. 
      if($this->_installer->run()===RInstaller::ERROR_NONE) 
      { 
       // Mark the user to have superuser privileges. 
       Yii::app()->user->isSuperuser = true; 
       $this->redirect(array('install/ready')); 
      } 

      // Redirect to the error page. 
      $this->redirect(array('install/error')); 
     } 
     // Module is already installed. 
     else 
     { 
      $this->redirect(array('install/confirm')); 
     } 
    } 
    // User is guest, deny access. 
    else 
    { 
     $this->accessDenied(Rights::t('install', 'You must be logged in to install Rights.')); 
    } 
} 

/** 
* Displays the install ready page. 
*/ 
public function actionReady() 
{ 
    $this->render('ready'); 
} 

/** 
* Displays the install ready page. 
*/ 
public function actionError() 
{ 
    $this->render('error'); 
} 

}

+3

你的數據庫連接是錯誤的,所以這會引發錯誤。這是非常基本的事情,請在問這樣簡單的問題之前去谷歌。 – 2014-10-09 13:23:21

+0

而你不應該給你密碼! – consuela 2014-10-10 10:00:50

回答

0

嘗試這樣,

'db'=>array(
        'connectionString' => 'mysql:host=localhost;dbname=sarish', 
        'class'=>'CDbConnection', 
        'emulatePrepare' => true, 
        'username' => 'sarish', 
        'password' => '[email protected]', 
        'charset' => 'utf8', 
        'tablePrefix' => '', 
      ), 
+0

Nop仍然不工作相同的錯誤 – Anish 2014-10-09 13:46:28

+0

請看看更新的安裝控制器coDe – Anish 2014-10-09 13:52:05

+0

檢查受保護的/配置/內main.php文件配置數據庫 – 2014-10-09 13:58:23

0

嘗試改變localhost到你的IP地址127.0.0.1並添加端口號,看看會發生什麼。

'connectionString' => 'mysql:host=127.0.0.1;port=3306;dbname=sarish', 
0

我有這個問題太,這是我在這裏的解決方案,我想你的雙重配置數據庫連接,MySQL錯誤:使用密碼:NO意味着你的密碼是空的....所以看一看/通用/ config/main-local.php,這裏有一個db連接的預配置,所以你不需要在任何其他配置文件中配置db連接.....我的英語不好,但我希望你能理解我..

相關問題