I know that PDO will throw an exception if the connection fails (assuming you enable
PDO::ERRMODE_EXCEPTION), but I want to test if a connection is still active, potentially hours later.
I have a long running script and after awhile it times out. Theoretically I can increase this amount of time with
PDO::ATTR_TIMEOUT but basically I want to write a function that gives me back an active connection -- either an existing connection if it's already been established and has not timed out or re-connect if it has.
Should I just do
SELECT 1, catch the exception, and re-connect? Or is there a nicer way?