Respected all, i'm in trouble. I created a file with name validation.php and store all my validation functionality in this file with different function names like,
check_textbox(parm1, pram2, pram3, pram4) { // Definition here }
check_chkBox(parm1, pram2) { // Definition here }
and so on.....!
then i created a table in mysql with the name tbValidation and stored all the function name with parameters in a table. the record stored in table look like as:
interfaceid---------- functionNameWithReturnValue
1 ------------ check_textbox(parm1, pram2, pram3, pram4) = 1
2 ------开发者_如何学Python------ check_textbox(parm1, pram2, pram4) = 0
3 ------------ check_textbox(parm1, pram2, pram4) = 1) AND (check_chkBox(parm1, pram2)=0)
when i fetch record from database i want to invoke those functions that store in validation.php
$data = mysql_fetch_array($drow);
if($db->row_count > 0)
{
// when i fetch row one from database. I used this one but not working
// @ $data[0] have value "check_textbox(parm1, pram2, pram3, pram4) = 1"
if($data[0])
{
// Do this
}
}
How i can do this task...? :(
First thing is to make your validation.php file visible from the file your are executing:
// doc: http://it.php.net/manual/en/function.require-once.php require_once("validation.php");
Then you have a choice:
// case 1: use function eval (http://php.net/manual/en/function.eval.php) // this will work if the parameter names stored as code in db are actually defined eval("\$ret = $data[0];"); // case 2: use function call_user_func (http://php.net/manual/en/function.call-user-func.php) // this if you extract the function name, and then need to programmatically manage the parameters call_user_func(function_name, parameters...);
Using the eval function has a lot of drawbacks though (bad performance, hard maintenance and readability of code, probably it is a symptom of bad design).
精彩评论