Luka
Luka

Reputation: 321

Reading php code from database

Lets say I want to save function in database. For example we have table function with attributes: function and function name. For saving function for time we would save it in data base:

time_funtion(){ return time() } and "Time".

I have no idea how to execute this function after reading from DB is this even possible?

I could do this with files - read from database then write it in file, then include file and calling this function will work. Any other ideas?

Upvotes: 0

Views: 503

Answers (3)

IEnumerable
IEnumerable

Reputation: 3790

Use eval("your PHP code here")

Upvotes: 1

Johannes Klauß
Johannes Klauß

Reputation: 11020

You can use eval() for this. But be careful what you save into your db. There are just a few problems where this is a useful approach. In 99% you don't need this and it's lacking security, because you are executing unkown code, which is not what you want.

Upvotes: 2

Rob
Rob

Reputation: 12872

I'm not sure why you'd want to do this but you could use eval()

Upvotes: 2

Related Questions