code extraction

I extracted two parts of the file sql.php as functions in sql.lib.php to show my re-factoring skills.