I have a section of code that, depending on the requested URL, will contain one of fourteen other files. Some of these fourteen files require a connection to one of three different databases, and additional files can be added at any time.
I do not want to open default PDO connections for all three databases, as this is a waste of resources and will slow down runtime. So my thought is to wrap all SQL queries inside a function. The first time the request is executed on an insecure PDO connection, the try {} error handler can catch it, find out what the problem is (in this case the connection does not exist), then open the connection and run the request again. Thus, the database is connected only as necessary, if only the connection string (host, database, username, password) is defined in advance, I do not see any problems with its operation.
However, I need to continue with this and not have access to the dev block for about 7 days, so can anyone see any problems with this script? Also, can someone tell me the error message that the handler-> errorInfo () will return if the connection does not open?
source share