Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

php - Doctrine: Persisting data into multiple databases (mysql/oracle) at same time?

Is it possible to configure Symfony/Doctrine in a way to write data into two different databases (mysql AND oracle) at the same time while reading data only from mysql ? The intention is to have an up to date copy in oracle all the time.

An alternative scenario would be to copy data from mysql to oracle with cron script using Doctrine using a cron script. Would this be possible without modifieing symfony php code ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can write to two different DBs and read from just one of them if you want. For that you have to create a separate entity manager for each particular connection. Look at this answer.

Inject the ManagerRegistry to your services and/or controllers to avoid injecting both managers. Like this:

public function __construct(ManagerRegistry $managerRegistry)
{
    $mySqlEm  = $managerRegistry->getManager('default');
    $oracleEm = $managerRegistry->getManager('oracle');
}

Keep in mind what that are synchronous operations and your app will be slower. I suggest you to investigate the mysql/oracle replication for your purposes, maybe something like this.

UPD As Cerad mentioned this approach won't solve the issue because requires separate entities for each manager.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...