Need Help SQL


#1

Here is my code. Its saying No Database Selected. Please explain.

<?php

$servername = "localhost";
$username = "root";
$password = "Colorado3";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "Database[Connected]";
}

//query
$sql = "SELECT * FROM tests";

if ($conn->query($sql) === TRUE) {
echo "EYYYY";
} else {
echo "Oops!" . $sql . "
" . $conn->error;
}

$conn->close();

?>


#2

Which excersise does this relate to?

Anyhow;
The mysqli connect statement expects a DB name in the connection string.
For example:

$servername = "localhost";
$username = "root";
$password = "Colorado3";
$database = "Yourdb";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);