At the moment,开发者_StackOverflow I'm handling them like this:
$query = mysql_query("...");
while ($results = mysql_fetch_array($query))
{
...
}
What are the more practical ways to go about this?
My question to you is: what's impractical about that?
It seems the ideal paradigm for processing your result set one row at a time. If that's what you need then that's what you need.
My only advice would be to ensure you only ask for the columns you need, and that you let the database do what it's best at. In other words, if you want aggregated results, that's something the database should do (rather than bringing down all records and aggregating on the client).
Regarding the need to do it all at once, there's not a lot of difference between something like (pseudo-code):
array_of_array = fetch_all()
and
array_of_array = empty
while (array = fetch_one()):
array_of_array.push (array);
Certainly not enough for the language developers to think it necessary, given the possible fetch
functions found here.
If you really need that functionality, you could probably code it up yourself. That's why most languages provide the ability to create user-defined functions, after all :-)
精彩评论