Personally, I would reorganize the code to disable access to the database directly from the main program and instead create a data access class that will be responsible for determining which actions were "read" and which actions were "written" and sending them to the appropriate server (s).
Thus, all the code that knows about slave / master configuration will be in one place, and you will not need to change your main program, except that it receives data from the Data Access class, just the opposite of the database.
source share