extractDatabaseToCsv function

Exports all the results from a database into csv files