# How do I execute PHP that is stored in a MySQL database?

I'm attempting to write a web page that calls PHP that is saved in a MySQL data source. The web page that is saved in the MySQL data source has PHP (and also HTML) code which I intend to work on web page load.

Just how could I deal with doing this?

34
2022-06-07 15:15:53
Source Share

You can consider the eval function in PHP. It permits you to run approximate PHP code. It can be a massive protection threat, however, and also is ideal stayed clear of.

2
2022-06-07 15:42:36
Source

eval() function was covered in various other feedbacks below. I concur you need to restrict use eval unless it is definitely required. As opposed to having PHP code in db you can have simply a class name that has actually method called, claim, execute(). Whenever you require to run your personalized PHP code simply instantiate the class of name you simply brought from db and also run ->execute() on it. It is much cleaner remedy and also offers you wonderful area of adaptability and also boosts website protection dramatically.

5
2022-06-07 15:40:37
Source

You can make use of the eval command for this. I would certainly advise versus this though, due to the fact that there is a great deal of challenges utilizing this strategy. Debugging is tough (emergency room), it indicates some protection threats (negative web content in the DB obtains implemented, uh oh).

See When is eval evil in php? as an example. Google for Eval profanes, and also you'll locate a great deal of instances why you need to locate an additional remedy.

Enhancement: Another excellent write-up with some referrals to ventures is this blogpost. Describes previous vBulletin and also phpMyAdmin ventures which were brought on by inappropriate Eval use.

33
2022-06-07 15:38:48
Source