Surely your just talking about something like
function foo()
{ print "hello"; }
stored in a field in a database that you can then exec at will.
you can store the code in a mysql text field. probably the same for mssql i dont know.
just insert like you would any other data.
then when you want the function - get the col data just like normal - then use the php command eval().
ull have to check the syntax in the manual.
ive done this loads of times with functions, classes and just regular code.
eval -ing this foo function would mean that then from your code you can run "foo();"