I'm still trying to figure out any scenario where you would need to rewrite the .htaccess on the fly, or even frequently enough that you would need to pull it from the database.
The reason it could be dangerous is if a hacker can trick your script into writing arbitrary values to the .htaccess file they can get redirects to other directories of your machine.
My own approach doesn't even use .htaccess since mod_rewrite applied at the httpd.conf layer is 10 to 20 times faster than when applied in htaccess. Apache looks for the file and if it doesn't find it then it hands off operational control to a PHP framework to resolve the request. The only thing that is unique to my approach is I'm doing it in httpd.conf. Drupal, Joomla et al do the same thing but at the .htaccess level since, like most php applications, they are of a 'drop this in your public_html folder and be done' approach.
dJango, in python, assigns itself as a directory handler in Apache, so all requests pass through this. This is a bit slower than letting Apache do it all, but not as slow as things would be if PHP handled all requests (which it isn't designed to do - python being a compiled language is better equipped for such an approach).
In each of these approaches though the code given to Apache to follow is very small and never changes once set. With that in mind I did write an automation script that can change the httpd.conf values for the framework - but this script isn't invokable from a web browser and must be invoked through ssh (and further using sudo), and second it is only invoked when I'm adding a new website project to the server, which might only occur once every couple weeks.
From a technical perspective it isn't too difficult to do this in PHP. .htaccess (and httpd.conf for that matter) are plain text files. A PHP script that opens a connection to the database and parses what it finds into a text file is very easily done - but seriously consider why you're wanting to do this because it appears to be (on the face of it) to be a very bad approach.