I would write the database text to a temporary file, and then execute the code afterwards in the temporary file...
sorta pseudo code:
$my_text = getDatabaseStuff();
$handle = fopen("some_file.php", "w");
fputs($handle,$my_text);
fclose($handle);
include "some_file.php";
...
Something like that, anyway 🙂