0
I would like to know how to use PDO with the function Eval(), since the way I use is generating error.
$id = "return $bd->fetchAll();";
eval("$id");
eval("return $bd->fetchAll();");
MISTAKES:
Notice: Undefined property: PDOStatement::$fetchAll in
Parse error: syntax error, unexpected ')' in
To call methods within a string, use
{ }
. change the two lines to:$id = "return {$bd->fetchAll()};";
eval("return {$bd->fetchAll()};");
– rray
Still keeps generating error...
– abcd
Try putting in variables. Ex:
eval("return \$bd->fetchAll();")
– MeuChapeu
What is the purpose of using the
eval()
?– rray
Now generates no error but also returns no data, Empty...
eval("return \$conn->fetchAll(PDO::FETCH_CLASS);");
without Eval returns normal the querys...– abcd
obviously it would not return any given because it only makes the return of the object.. By the way, saw the above question? What is the reason for use of Eval ?
– Daniel Omine
documentation evil ;)
– rray
Goal that is a class, where I won’t keep putting is "Fecht" does it, is fetchAll does it.. and so on... from there to facilitate my life, I pass the method by string...
– abcd
But then it returns the object and I give a var_dump to check what was returned... With Eval comes empty, typing the code returns all the data...
– abcd
Solved like this:
$id = "return \$conn->fetchAll(PDO::FETCH_CLASS)";
eval("\$id;");
– abcd
Regardless of your solution, there’s a 99.99% chance that you’re making terrible use of
eval
. If you explain in detail the problem you are trying to solve with this (it may be in another question), I’m sure the staff will help you find a better solution withouteval
.– bfavaretto
As I said above, I created a class where one would fetch or fechAll or other PDO methods... I would not like to put one by one... there in the method I created, say, I write:
$this->pega('fetch');
then he would add the fetch method,$this->pega('fetchAll');
then use the fetchall dowry... there are various and various methods in the PDO, the would go bad. Imagine that after fetch all, I would like to count the number of values found in the search... com Val, I could call more methods, without specifying in my class, If fetch, do it, if Fetchall does it .– abcd
Then I’d put right what I want:
$this->pega('return $conn->fecthAll(); if($conn->rowcount() >= 1)'){faz isso}
... I could add a lot more to my code...– abcd