When i connect to the database, i try to handle the error that the database is down. But i seem to be unable to suppress this warning:
Warning: PDO::__construct() [pdo.construct]: php_network_getaddresses: getaddrinfo failed: Name or service not known in * on line 29
{"status":false}
what should be there:
{"status":false}
the code for the error handling:
try
{
$pdo = new PDO("mysql:host={$host};dbname={$db}", $us, $pw,array(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION));
}
catch(PDOException $ex)
{
echo '{"status":false}';
}
The PDO errormode is set to PDO::ERRMODE_EXCEPTION so it should not throw a warning at all. It should throw a fatal error that i can catch..
the problems seems to be that it throws this warning if it cannot solve the dns
Solution at an @ to suppress the warning
@$pdo = new PDO("mysql:host={$host};dbname={$db}", $us, $pw,array(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION));