Search code examples
phpmysqli

mysqli_select_db() expects parameter 1 to be mysqli, string given


I am getting these errors:

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in D:\Hosting\9864230\html\includes\connection.php on line 11

Database selection failed:

<?php
require "constants.php";

// 1. Create a database connection
$connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);

// 2. Select a database to use 
$db_select = mysqli_select_db(DB_NAME,$connection);

Solution

  • Your arguments are in the wrong order. The connection comes first according to the docs

    <?php
    require "constants.php";
    
    // 1. Create a database connection
    $connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);
    
    // 2. Select a database to use 
    $db_select = mysqli_select_db($connection, DB_NAME);