Broke sql.php up into functions