Hello Yii developers :)
Im new in yii freamwork, I want to have a independent database for my module, so I create a db config in my module like this:
1-first I create db.php file that return db config
<?php
/**
* Created by PhpStorm.
* User: Rezvania
* Date: 3/10/2018
* Time: 11:31 AM
*/
return[
'class'=>'yii\db\Connection',
'dsn'=>'mysql:host=localhost;dbname=db_entry_mdu',
'username'=>'root',
'password'=>'',
'charset'=>'utf8',
'tablePrefix'=>'tbl_entry_mdu_'
];
2-so i create config file that modify my module configs
<?php
/**
* Created by PhpStorm.
* User: Rezvania
* Date: 3/10/2018
* Time: 11:30 AM
*/
$db=require __DIR__.'/db.php';
return[
'defaultRoute'=>'entry',
'components'=>[
'db'=>$db,
]
];
3-finaly I set that in my Module class
<?php
/**
* Created by PhpStorm.
* User: Rezvania
* Date: 3/10/2018
* Time: 11:26 AM
*/
namespace app\modules\entry;
use yii\base\Module;
use yii;
class EntryModule extends Module
{
public function init()
{
parent::init(); // TODO: Change the autogenerated stub
\Yii::configure($this,require __DIR__.'/config/config.php');
}
}
now when I try to use of tables data I get this error:
The table does not exist:
tbl_entry_mdu_user