I see no alternative but to create an appropriate solution for the analysis of the result. honestly that the database has a bad design is not an excuse not to give it a solution ... and the best solution is to work with the data in the backend:
// Conection to database
$conn = new PDO("...
You have 2 servers; 12 MySQL instances?
On each of the 2 servers, do one or the other of:
Plan A: Multiple MySQL instances, each using a different my.cnf, Port, and base directory.
Plan B: Multiple Dockers, each with one MySQL instance. Configure Docker config maps incoming different port numbers to 3306. You should probably use a "volume" so ...