Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mysql

I'm trying to write a page that calls PHP that's stored in a MySQL database. The page that is stored in the MySQL database contains PHP (and HTML) code which I want to run on page load.

How could I go about doing this?

like image 219
different Avatar asked Sep 03 '08 10:09

different


People also ask

Can I run PHP in MySQL?

In order to connect a MySQL database to PHP, you require MySQL on your computer, a tool to create and manage databases, and PHP installed. The most popular ways to connect a PHP script to MySQL are MySQli and PDO.


1 Answers

You can use the eval command for this. I would recommend against this though, because there's a lot of pitfalls using this approach. Debugging is hard(er), it implies some security risks (bad content in the DB gets executed, uh oh).

See When is eval evil in php? for instance. Google for Eval is Evil, and you'll find a lot of examples why you should find another solution.

Addition: Another good article with some references to exploits is this blogpost. Refers to past vBulletin and phpMyAdmin exploits which were caused by improper Eval usage.

like image 133
Erik van Brakel Avatar answered Sep 23 '22 22:09

Erik van Brakel