Switch betwenn databases using ajax php : I am trying to switch between databases connection ( just change hostname ) depend on choosed DB name.

I got `<a>` tags with values.

    <div class="user-menu dropdown-menu">
        <a class="nav-link" href="db" id="db_one"><i class="fa fa-database"></i> DB 1</a>
    
        <a class="nav-link" href="db" id="db_two"><i class="fa fa-database"></i> DB 2</a>   
    </div>

Now I am checking which `<a>` is clicked then taking value `db_one/db_two` and send it by ajax to my php connecting file.

        $("a[href='db']").click(function(e){
            e.preventDefault();
            var hostname = e.target.id;
             console.log(hostname);
             $.ajax({
          url: 'connection.php',
          data: hostname,
          type: "post",
          success: function () {
              alert('done');
              console.log('this is: '+hostname);
              location.reload();
          },
      });
        });

I am reloading page to "reconnect" with db.

And finally there is my php connection.

    <?php
    
    $host = $_POST['hostname'];
    $hostname = $host;
    
    switch ($hostname) {
        case "db_one":
        $conn = mysqli_connect("$hostname", "my_user", "my_password", "my_db");
        if($conn === false){
        
            die("ERROR: Could not connect. " . mysqli_connect_error());
        
        } else {
          echo "<script>console.log('connected');</script>";
        }
        break;
        case "db_two":
        $conn = mysqli_connect("$hostname", "my_user", "my_password", "my_db");
        if($conn === false){
        
            die("ERROR: Could not connect. " . mysqli_connect_error());
        
        } else {
          echo "<script>console.log('Polaczenie z baza nawiazane');</script>";
          echo "<script>console.log('connected');</script>";
          
        }
            break;
        default:
        $conn = mysqli_connect("localhost", "my_user", "my_password", "my_db");
        if($conn === false){
            die("ERROR: Could not connect. " . mysqli_connect_error());
        
        } else {
          echo "<script>console.log('default connect');</script>";
          
        }
    }
    
    ?>

Where is my fault? I still got default connection