I noticed that PDO displays warnings to the end client. For example, if an invalid enum value is being set, it shows a warning:
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'type' at row 1
There is no reason for end user to see this. I'd much rather just display 500
status code, although it is users fault so 400 would be more appropriate.
These are my current pdo options:
public static array $options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
and i am using
error_reporting(E_ALL);
ini_set('display_errors', 0);
at the top of the script.
Any idea why this is happening?
Minimal code with intentional incorrect values when display_errors
is set to 1:
$stmt = $this->pdo->prepare("INSERT INTO MYTABLE (`type`) VALUES (?)");
$stmt->execute([$json->type]);
Full message without stack trace
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'type' at row 1
Fatal error: Uncaught PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'type' at row 1 in path/api/v1/index.php:35