0

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

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Rezvania
  • 59
  • 6
  • 2
    So check your database, do you really have `tbl_entry_mdu_user` there? – u_mulder Mar 11 '18 at 08:19
  • yes, I'm sure that i have this table, but now my main question is that can i have a independent db for my modules in Yii? or Not!? – Rezvania Mar 11 '18 at 08:35
  • Possible duplicate of [Multiple database connections and Yii 2.0](https://stackoverflow.com/questions/27254540/multiple-database-connections-and-yii-2-0) – M. Eriksson Mar 11 '18 at 08:40
  • thanks, Now i know that i can have multiple databases, but my problem staying yet. – Rezvania Mar 11 '18 at 08:56

0 Answers0