php - Yii2 Modules and configuration -


i'm not 100% sure module right way go here. thought i'd ask. use case have large application powered oracle db.

we have db isn't oracle , involved in different type of work , different user group, thought should use module - right? if not what's best way achieve kind of set up?

if so, there way configure second db within module or should done within main app/config/dp.php file?

since, using yii2-basic application. so, directory structure like.

root folder     -> assets     -> commands     -> components     -> config         -> console.php         -> db.php         -> params.php         -> web.php     -> controllers     -> mail     .     .     . 

your database connection details present in db.php. now, want database play important rle in application. no worries. create 1 more database connection details in,say, db2.php inside config folder.

db2.php

<?php  return [   'class' => 'yii\db\connection',   'dsn' => 'mysql:host=localhost;dbname=another_database_name',   'username' => 'username',   'password' => 'password',   'charset' => 'utf8', ]; 

so, directory structure :

root folder     -> assets     -> commands     -> components     -> config         -> console.php         -> db.php         -> db2.php         -> params.php         -> web.php     -> controllers     -> mail     .     .     . 

now, next step include db2.php in application.

open web.php. add 1 more line db2.php

<?php  $params = require(__dir__ . '/params.php');  $config = [     'id' => 'basic',     'basepath' => dirname(__dir__),     'components' => [         .         .         .         'db' => require(__dir__ . '/db.php'),         'db2' => require(__dir__ . '/db2.php'),     ], ]; 

so, database connection set successfully. now, next step use query related database connection.

$row = yii::$app->db2->createcommand("select * `table_name`")->queryone(); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -