-2
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'.

Genapex
  • 1
  • 1
  • 1
  • 2
  • 1
    It should be `....or die ('Could not select ' . $db_name . ': ' . mysqli_error($db_connect));` – Darren Jul 29 '14 at 06:05
  • That didn't really solve anything. Still not getting any errors and it's still not working properly either. I don't know why it's not connecting to the database. – Genapex Jul 29 '14 at 06:07
  • FYI, `mysqli_connect` / the `mysqli` constructor will **NEVER** return a *falsey* value so you can forget about using `or die()` (which you should never use anyway). Also, you can pass the *dbname* parameter in as the fourth argument to `mysqli_connect()` – Phil Jul 29 '14 at 06:16

1 Answers1

8

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);
m1k1o
  • 2,344
  • 16
  • 27