one of one of many questions i had when i was staring to program in php was how can i run code from a database. i mean, all the time i wrote my code on a file then saved it as example.php and display it with my browser.

but wouldn't it be cool if i could run php code from a database string.

let say i have this on mysql database in one of my table fields:
CODE:
$foo = mysql_fetch_array(mysql_query("Select * FROM table_name where date=$today" ,$db_conn))

echo $foo;


so if were to query my table and print this on my script this is how it would look like

OUTPUT:
today's date is date('m/d/Y')


of if i wanted to really run the date() function from the varirable $foo i would have to use the eval function in php and can run my code like this:

CODE:
echo eval("\$foo = \"$foo \";");

OUTPUT:
today's date is date('05/25/2007')


this is the information i have on eval

eval

(PHP 4, PHP 5)

eval — Evaluate a string as PHP code
Description
mixed eval ( string $code_str )

Evaluates the string given in code_str as PHP code. Among other things, this can be useful for storing code in a database text field for later execution.

There are some factors to keep in mind when using eval(). Remember that the string passed must be valid PHP code, including things like terminating statements with a semicolon so the parser doesn't die on the line after the eval(), and properly escaping things in code_str. To mix HTML output and PHP code you can use a closing PHP tag to leave PHP mode.

Also remember that variables given values under eval() will retain these values in the main script afterwards.

if you really want learn more information go to:

http://www.php.net/manual/en/function.eval.php