You just use: mysql_close($connection); somewhere in your code and continue to work on your database.
Move mysql_close($connection); to the line after you finish working on your database.
Example:
$connection = mysql_connect(...);
mysql_select_db(...);
SELECT ...
INSERT INTO ...
mysql_close($connection);