My guess is that the error occurs while trying to decipher your hand-rolled error JSON. Simply put, never produce JSON manually. Change your exception handler to this...
catch (PDOException $e) {
error_log($e->getMessage(), 3, '/var/tmp/php.log');
http_response_code(500);
echo json_encode(['error' => ['text' => $e->getMessage()]]);
}
Assuming you have PDO set to throw exceptions, get rid of the or die()
statements.
You are also calling $stmt->execute()
twice as well as closing the connection before you're done with it. Your code will work better as...
try {
if (!isset($user->experiencie)) {
throw new Exception('Missing "experiencie" request parameter');
}
$db = PDOConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam(':experiencie', $user->experiencie);
$stmt->bindParam(':id', $id);
if ($stmt->execute()) {
$response['error'] = false;
$response['text'] = 'Good!';
} else {
$response['error'] = true;
$response['text'] = 'Bad!';
}
echo json_encode($response);
} catch (Exception $e) {
error_log($e->getMessage(), 3, '/var/tmp/php.log');
http_response_code(500);
echo json_encode(['error' => ['text' => $e->getMessage()]]);
}