Modified code for MySQL DB implementation