Migrating to new DBAL but need to maintain legacy database connection
Background
The application I am working on currently uses mysql_query statements all over and we want to migrate to the Doctrine DBAL.
There are thousands of usages of the mysql_query function and we would like to start new development using the new DBAL and upgrade the old code as we go as opposed to trying to update it all at once.
Question
开发者_如何转开发What is a strategy for managing the multiple database connections (one for the old mysql_connect and for the Doctrine DBAL (PDO)) during a single page render without significantly limiting performance or increasing resource usage?
I can't think of a particularly clever way of doing it.
I think your best bet is to simply maintain two separate database connections for requests that use DBAL. If you're smart about your new code, you'll want to make sure the DBAL connection is only established on first use (as opposed to in some bootstrapping process for your app). That way, requests that only execute legacy code avoid the DBAL overhead.
I can't think of a quick, unintrusive way of making your legacy connection lazy-load, but since you know your code, you might.
精彩评论