Add allow_bail Argument for wpdb->check_connection() the Same as for db_connect()
|Reported by:||DrProtocols||Owned by:||pento|
The new wpdb check_connection() function is a great addition and potentially allows plugins to change to using that function rather than having to use their own (especially good now that there is at the mysql/mysqli thing to be considered).
However, as it bails by default (unless the template_redirect action has been done) this causes a problem for plugins that handle the broken and cannot reconnect failure themselves.
The db_connect() function has an allow_bail argument that allows the caller to prevent the bail action and simply have db_connect() return false if a connection failure occurs.
Adding the same argument and functionality to check_connection() (defaulting to true as it does for db_connect()) would allow the caller to to have check_connection() return false on a failure and allow the caller to handle the failure.
This would provide a behavioural consistency between the two functions as in effect they are both trying to connect to the database.
The call to db_connect() from within check_connection() would still call with false regardless of the value that check_connection() was called with.
(I don't believe that the template_redirect action can be guaranteed to have been "done" under every possible scenario where a plugin might want to check a database connection which is why I believe the additional argument and associated logic is required. For example, would template_redirect have been called if a background (cron) task were being executed? This condition seems too uncertain to be relied upon).
Change History (8)
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
19 months ago
- Keywords 2nd-opinion added
- Milestone changed from Awaiting Review to 3.9
- Keywords has-patch commit added; 2nd-opinion removed
- Owner set to pento
- Status changed from reopened to accepted