Is there any method to close connection similar to mysql_close()
for wpdb
in WordPress?
Is it not necessary to close connection for global wpdb
?
1 Answer
WP 4.5 had introduced wpdb->close()
method to close connection in current instance.
Old answer
There is no explicit method. It stores link identifier in $wpdb->dbh
field, but it is protected, so not convenient to run close on.
-
-
@Brij unless I am missing something it should be closed automatically when page finishes loading and PHP ends execution.– RarstCommented Feb 1, 2011 at 9:53
-
"This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0."– jgraupCommented Nov 2, 2016 at 2:30
-
1@jgraup cheers, updated answer with info about new method which handles that.– RarstCommented Nov 2, 2016 at 9:32
-
1@D.JCode if you are reusing global
$wpdb
you definitely shouldn't close it, it's just a single connection for everything and not a problem. You would only want to explicitly close if you are creating a lot of new wpdb instances (not something I ever seen done in WP).– RarstCommented Dec 23, 2020 at 18:35