WordPress choose wrong database

In case someone is interested. I made it work.

I made a plugin and in the main php-file I wrote this.

<?php

function ir_load(){
    include_once(ABSPATH . 'load.php');
}

function db_fix_login(){
    global $wpdb;
    $wpdb->select(DB_NAME);
}

add_action("wp_head","db_fix_login", 0);

ir_load();
db_fix_login();

?>

The ir_load() contains the database connection to my database. I made it a function in case I needed to change or include it somewhere else.

db_fix_login needed to go to wp_head() (since I use get_header() on my subpage to keep wordpress functionality).

Everything worked except that I got logged out all the time if I only runned ir_load().

So after trying everything: Why not run db_fix_login() right after? It worked. No errors or anything!

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