moving out sql_function

This pull request is about moving out all the sql function to a sql_function.php page.