0

I get the error message: Connection failed: Unknown database 'first'

 <?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "first";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT id, name, age FROM table";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - name: " . $row["name"]. "age: " . $row["age"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

The database I'd like to select is there, but I get the error over and over

scylla0120
  • 131
  • 1
  • 8

0 Answers0