Changed to use database procedures instead of sql

Changed from mysql driver to mysqli driver, safer