Search code examples
phpmysqlmysql-connect

mysqli_select_db() not working properly ..?


function db_connect($db_host, $db_user, $db_pass, $db_name) {
    $db_connect = mysqli_connect($db_host, $db_user, $db_pass) or die('Could not connect: ' . mysqli_error($db_connect));
    $db_select = mysqli_select_db($db_name, $db_connect) or die ('Could not select ' . $db_name . ': ' . mysqli_error($db_select));
}

Every variable is defined. All that appears is

Could not select CMS:

There isn't even an error message. What am I doing wrong? As far as I am aware, it is connecting to MySQL, but it isn't connecting to the specified database 'CMS'.


Solution

  • According to php.net, mysqli_select_db exepts to be first parameter MYSQLI link, seccond DB Name

    bool mysqli_select_db ( mysqli $link , string $dbname )
    

    http://php.net/manual/en/mysqli.select-db.php

    You should turn on error reporting for next time, to catch that error.

    error_reporting(1);