I was experimenting with try
catch
and found some strange behaviour.
The code
<?php
$user = "WrongUserName";
$pass = "WrongPassword";
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
echo "Success";
}
catch (PDOException $e) {
echo "Login Failed";
}
?>
This outputs "Login Failed" as expected, but when I delete variables
<?php
// Variables for $dbh is missing
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
echo "Success";
}
catch (PDOException $e) {
echo "Login Failed";
}
?>
It outputs
Notice: Undefined variable: user in C:\xampp\htdocs\simpleBD\db.php on
line 6
Notice: Undefined variable: pass in C:\xampp\htdocs\simpleBD\db.php on line 6
Success
WHY does is output the "Success" instead of "Login Failed"