fixed db error handling for prepared statements