How can JavaScript code be added before the closing HTML body tag?

With WordPress, JavaScript cannot be output directly to the browser from PHP. You must use WordPress functions like wp_enqueue_script (please read the Notes from the documentation for details) from within an action hook handler for wp_enqueue_scripts.

WordPress documentation for wp_enqueue_scripts says:

wp_enqueue_scripts is the proper hook to use when enqueuing scripts and styles that are meant to appear on the front end. Despite the name, it is used for enqueuing both scripts and styles.

To put the script before the end </body> tag use the $args parameter of the wp_enqueue_script function by setting the in_footer property to true. For example:

/**
 * ... enqueue plugin scripts.
 */
function load_plugin_scripts() {
    wp_enqueue_script(
        'script-handle-name',
        plugin_dir_url( __FILE__ ) . '/js/script.js',
        array(), // Dependencies. Array of script handles for other scripts this script depends on.
        '1.0.0', // Version number.
        array(
            'strategy'  => 'defer'
            'in_footer' => true
        )
    );
}
add_action( 'wp_enqueue_scripts', 'load_plugin_scripts' );

For some background and another example, see my answer to this Stack Overflow question: How to include .js in html from wordpress plugin?.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)