Fix database calls to use PDO safely