Since the "users" table does not exist, I would like to understand why instead of catch
is executed, the "errors" function is executed
Code:
<?php
$usuario = 'root';
$senha ='';
function errors($e)
{
echo "Erro dados";
}
set_exception_handler('errors');
try
{
$conn1 = new PDO('mysql:host=localhost;dbname=teste',$usuario, $senha);
}
catch(Exception $e){
echo 'Erro ao conectar com o banco';
die();
}
try
{
$sql= "SELECT * FROM usuarios";
$resul = $conn1->query($sql);
$resul = $resul->fetch(PDO::FETCH_ASSOC);
foreach ($resul as $key => $value) {
echo $key .": ". $value. "</br>";
}
}catch(Exception $e)
{
echo "Erro ao selecionar dados";
die();
}