How to use PDO in eval ()

0

I would like to know how to use PDO with the eval () function, since the way I use is generating error.

$id = "return $bd->fetchAll();";
eval("$id");
eval("return $bd->fetchAll();");

ERRORS:

 Notice: Undefined property: PDOStatement::$fetchAll in 
    Parse error: syntax error, unexpected ')' in
    
asked by anonymous 16.03.2015 / 23:46

1 answer

0

Attention

I do not know why you want to do this, but I already warn you in advance that using eval is almost always considered bad practice.

But I'll answer anyway.

Response

For this to work, you have to escape the $ siffer with a \

So:

eval("return \$bd->fetchAll();");
    
18.08.2015 / 21:07