Running PHP code from Database

First of all create a Database and run/import the following SQL:

`id` int(11) NOT NULL auto_increment,
`contents` text collate latin1_general_ci NOT NULL,

INSERT INTO `test` (`id`, `contents`) VALUES
(1, ‘for($i=1;$i<=10;$i++){echo $i.”<br />”;}’);

And then run the following code:

* Running PHP code from Database
* @author      Md. Nazmul Basher (
* @Web
* @Mobile        +8801712994064

class runPHP
var $server;
var    $username;
var $password;
var $db;
var $link;

function __construct($server, $username, $password, $db)
$this->server = $server;
$this->username = $username;
$this->password = $password;
$this->db = $db;

function connect()
$this->link = mysql_connect($this->server, $this->username, $this->password);
mysql_select_db($this->db, $this->link);

function runPHPfromDB()
$query=”select * from test”;
$result = mysql_query($query);
$data = mysql_fetch_array($result);
eval($data[‘contents’]); // Evaluate a string as PHP code

function __destruct() {

} // End Class

$res = new runPHP(‘localhost’,’root’,”,’test’);


One Response to Running PHP code from Database

  1. manchumahara says:

    that means eval is the key here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: