My suspicion is that there’s a PHP error in the function. For example, you are using $wpdb
but to use this object inside a function you need to declare it global $wpdb;
.
Turn on error reporting, you’ll probably want to do it using a log rather than displaying them, put this in wp-config.php, https://codex.wordpress.org/WP_DEBUG
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);