port of database code to mysql