I know this question has been there many times, but no answer works for me.
My PDO just doesn't throw any error... or something catch the error before me.
I'm quite new to php, and I hate to not understand simple things.
Here's my initialization code
$pdo = new PDO("mysql:host=" . $db['host'] . ";dbname=" . $db['dbname'], $db['user'], $db['pass']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
and an example where I'm, for example, inserting a duplicate row with an unicity constraint (but same problem for unknown row, or any pdo exception...)
$columnString = "....";
$valueString = "....";
$sql = "INSERT INTO " . $table . " (" . $columnString . ") VALUES (" . $valueString . ")";
try {
$stmt = $this->pdo->prepare($sql);
foreach($request_data as $key => $value){
$stmt->bindValue(':' . $key,$request_data[$key]);
}
$stmt->execute();
} catch (PDOException $e) {
return null;
}
Of course, this code works well when no database problem occurs.
I'm using Slim 3 framework, and php7. Same problem with php5.
Does it have something to do with the framework? Is there other configurations ? Why the hell exceptions are not caugh?