Online Shopping : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

23 of 39 people (59%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

how can i store php code & query in mysql database and get all to execute when retrieved

Mar 15th, 2008 18:08
ha mo, Matthew Wilkinson, mr robinsf,


You can just store them as strings in the database, and then when you
retrieve them from the database just run them like this:
eval($PHPcodefromdatabasestring);
Here is an example of the full code:
$PHPcode = "echo \"This PHP code was taken from a database\";";
mysql_query("INSERT INTO tablename SET column='" . $PHPcode . "'");
$result = mysql_query("SELECT column FROM table");
$PHPcodefromDB = mysql_fetch_row($result);
eval($PHPcodefromDB);
This should output:
This PHP code was taken from a database
http://www.tantofa.com
http://www.fantofa.com
http://www.mantofa.com
http://www.tanpola.com
http://www.tampola.com
http://www.mozmar.com
http://www.yamot.com
http://www.templatestemp.com