Entry
Is there a way to store scripts in a database, and run them w/o >> file.name \n include file.name?
Aug 4th, 2004 15:51
J. Amgine Neilson, Cinley Rodick, John Marc, Amgine Neilson, http://us3.php.net/manual/en/function.eval.php
To process a section of script stored in a database, retrieve the script
from the database and process it using the <b>eval()<b> PHP function.
<?php
// connect to database
if (!$db_resourceid = mysql_connect($dbhost, $dbuser, $dbpass)) {
die ('Unable to connect to database host <br />'.mysql_errno().' :
'.mysql_error();
}
// select database
if (!mysql_select_db($dbname, $db_resourceid)) {
die ('Unable to select database <br />'.mysql_errno().' :
'.mysql_error();
}
// retrieve script
$query = 'SELECT script FROM script_storage WHERE script_id =
"'.$script_id.'"';
$result = mysql_query($query, $db_resourceid);
$fetched = mysql_fetch_array($result, MYSQL_ASSOC);
// process the the script
$script_return = eval($fetched['script'])
?>