You don't have to do any of this. You can have PHP generate just about any type of content, and deliver it in any way a browser knows how. For example:
<? //Generate text file on the fly
header("Content-Disposition: attachment; filename=savethis.txt");
// do your Db stuff here to get the content into $content
print "This is some text...\
Save that php script as text.php then in your html file,
<a href="text.php">Save this</a> - clicking on that link would cuase the save as dialog to pop up...
I'm a little alte to this question, but hopefully it'll help someone in the future.