-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using "while" statement while "selecting" #1
Comments
Thanks, good question! You seem to be referring to the difference between the following two approaches: $rows = $stmt->fetchAll();
// ...
// vs
while ($row = $stmt->fetch()) {
// ...
} First, performance in terms of execution speed is quite similar for these two approaches, and the first approach might even be a little bit faster. What you have in mind is probably memory consumption, though. For very large result sets, the second approach may actually use a lot less memory if you are executing an unbuffered query. You can only take advantage of this and the effect does only materialize if you process the data right away, i.e. inside the loop, and don’t need access to the whole result set outside of the loop anymore. So if you build an array inside the loop manually, you can just use the first approach instead. In modern applications, you often don’t output data immediately but pass data to a templating engine which inserts them into the (HTML) templates. In that case, you will usually have to use the first approach, anyway. But the second approach still has several use cases where it is preferable. You’re right. Internally, we use the first approach for the We should add another method that uses the second approach, just like $pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); for MySQL, so that you can really take advantage of the reduced memory consumption. |
Does your library support unbuffered query? |
No, not at the moment. That’s because buffered queries are really what you want with the methods that this library currently offers, and unbuffered queries would only be useful with that new query method that could be used with loops. If we add that method, we’ll probably use unbuffered queries there. |
Let’s keep this open because this is something we should definitely implement at some point in the future. Thanks again for the feedback here! |
I guess using "while" statement while "Selecting" is not possible right?
Using "while" statement while "Selecting" much better for performance. Because storing the data in a variable then looping to edit something is not preferred.
The text was updated successfully, but these errors were encountered: