Version modified to use it with MySQL or PostgreSQL