B
B
banny_name2015-10-17 20:41:49
PHP
banny_name, 2015-10-17 20:41:49

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>';

Result:
1:
array(2){
все что нашло...
}

2: Why is it so, and how would it be more correct to clone? array(0){}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-10-17
Protko @Fesor

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 question

Ask a Question

731 491 924 answers to any question