implemented CSV export

and some bugfixes to PDO