How can I store PHP code inside of a MySql table?

I’m wondering, if anybody can help inserting php code in mysql table via HTML form fields?


Can you give an example of what you’re trying to accomplish?

Databases are intended to store data, not blocks of code.

Thanks for your reply …

For example: A value is defined in php like “define(“YEAR”,date(“Y”));”

Now, I’d like this “YEAR” value to be printed on site after its being add into site DB through back-end admin panel using html form fields such as textfield or textarea.

For Example:

If posted value of a textfield is like “Sale “.YEAR.”, on Shoes & Sandals at …”

>> should be printed as “Sale 2013, on Shoes & Sandals at …”

Hi M.King, welcome to the forums.

Sorry, but I’m confused by your example.

Why not just call date() in your code instead of calling the database for a CONSTANT value? (wouldn’t it be better as a variable?)

I’m wondering if you’re trying to bang something into doing something that could be done in a better way.

Storing code in a database could be risky business as running it would probably use eval() IMHO not worth doing this way, if not for security reasons, to reduce resource use.

If you are merely dealing with simple string replacement I would recommend using a token system. You could implement something as simple as {DATE} than use str_replace() to replace the date within the user supplied content held in the database. Of course you could expand this to be as complex as necessary to achieve the given requirements of your specific requirements so far as to creating a language on top of php. However, I would recommend against this only allowing simple token replacement.