2011-02-01 35 views
0

我的eval代码中的问题在哪里? 因为Apache说:在eval()中解析错误 - eval()'d代码

Parse error: syntax error, unexpected T_STRING in E:\xampp\htdocs\1php\mas_res\inc\mysql_class.php(120) : eval()'d code on line 1

我的代码:

  $type1 = "row"; 
      $query1 = mysql_query("SELECT * FROM table"); 
      $textToEval = "mysql_fetch_{$type1}($query1);"; 
      $query = eval($textToEval); 

什么是正确的模式?

谢谢..

+0

回显出你的`$ textToEval`,并将它添加到你的问题中。 – jondavidjohn 2011-02-01 19:09:03

回答

5

不要使用eval!使用PHP的variable functions

$function = 'mysql_fetch_' . $type1; 
$query = $function($query1); 

哦,如果你想知道,什么是错:你忘了逃避$query1$。它应该是\$query1

+0

eval()是邪恶的(),请记住! :) – Trufa 2011-02-01 19:39:16