fixing PDO bugs and enhancing the exception handling