Answer the question
In order to leave comments, you need to log in
Why is PDO::fetchAll() cleared after the first use?
You need to use fetchAll() 2 times,
1 - to save to a variable.
2 - for AR
1..
echo '<br><pre>';
var_dump($this->db->STH->fetchAll());
echo '</pre><br>';
2..
echo '<br><pre>';
var_dump($this->db->STH->fetchAll());
echo '</pre><br>';
array(2){
все что нашло...
}
array(0){}
Answer the question
In order to leave comments, you need to log in
problem explanation - fetchAll takes all the data to the end. Obviously yes? What this means in practice is that when we execute a query, the database returns us a pointer to the beginning of the result, we do not yet have the entire result. Having made fetchRow, we take the first result, the pointer moves to the next line, and so on. Therefore, when we no longer have a result, we get null.
It's the same with fetchAll. The second time will not work.
p.s. Reconsider how you work with data. Use fetchAll once and reuse the result for whatever you want weird there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question