Why is connect_error not executing when failing to connect to database?

Viewed 20

When I write the right login details I successfully connect to the database and the echo statement "Connected successfully" is executed. But when I intentionally write wrong login details the die("Connection failed: " . $conn->connect_error); is never executed. Why is this?

<?php
//connect to MySQL database object-oriented style

$servername = "localhost";
$username = "username";
$password = "password";
$database = "databasename";

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

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

echo "Connected successfully";
?>
0 Answers
Related