Reputation: 21
Actually i create a application and please someone say me. how to establish connection with mysql and different oracle server. and how to update if update my mysql field so automatic update my oracle erp system.
Upvotes: 0
Views: 305
Reputation: 1314
Use Paritosh Mahale link. Assume you have OracleModel with getDb() returning oracle connection and MySql model with getDb() returning mysql connection. Then in MySql model define afterSave event hendler:
public function afterSave()
{
$oracleModel = OracleModel::findOne(/* condition */);
$oracleModel->someField = 123;
$oracleModel->save();
}
Upvotes: 0
Reputation: 1842
Follow the link that @Paritosh Mahale has commented up:
Multiple database connections and Yii 2.0
as regards the part of updating the fields in a database you can use migrations in these ways:
/yiic migrate # The default component db
/yiic migrate --db=db1 # Connection db component mysql
/yiic migrate --db=db2 # Connection oracle component db
and you need to run the same migration command on both databases with different option --db
.
Or you can override the init()
method of yii\db\Migration
:
<?php
use yii\db\Migration;
class m150101_185401_create_news_table extends Migration
{
public function init()
{
$this->db = 'db2';
parent::init();
}
}
and use like this: /yiic migrate
This migration will be applied to db2.
If you have multiple migrations that use the same database, it is recommended that you create a base migration class with the above init()
code. Then each migration class can extend from this base class.
If you want to have separated path of migrations for each database connections you can do like this:
yii migrate --migrationPath=@app/migrations/db1 --db=db1
yii migrate --migrationPath=@app/migrations/db2 --db=db2
...
For apply migrations "automatic" in each database in one command you can (just an idea) extend yii\console\controllers\MigrateController class and add a property public $dbs
. After you can add that property to options()
so when you call the migrate command you can pass a param like this:
/yiic migrate --dbs=db1,db2
and so you can manage that parameter for executing a migration for each
$dbs;
[Edit]
Some parts of the answer were taken from here: Migrating Multiple Databases
Upvotes: 1