+// Call-back function for running shutdown functions and close database connection
+function __SHUTDOWN_HOOK () {
+ global $link;
+
+ // Call the filter chain 'shutdown'
+ RUN_FILTER('shutdown', null, false);
+
+ if (is_resource($link)) {
+ // Close link
+ SQL_CLOSE($link, __FILE__, __LINE__);
+ } else {
+ // No database link
+ ADD_FATAL(NO_DB_LINK);
+ }
+}
+
+// Register shutdown hook
+register_shutdown_function('__SHUTDOWN_HOOK');
+