Forum Moderators: coopster

Message Too Old, No Replies

mysql_unbuffered_query

Does anyone use this? Then tell me how...!

         

mipapage

1:44 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP.net: mysql_unbuffered_query [es2.php.net]

Hey all, I came across a reference to this function somewhere today, and gave it a shot. I tried it out by simply replacing mysql_query in a simple little while loop:

$result = mysql_unbuffered_query($querydata);  
while ($row = mysql_fetch_array($result)) { //Do Something
}

It gave me the following error:

Notice: mysql_query(): Function called without first fetching 
all rows from a previous unbuffered query

There is a second query that immediately follows the aforementioned, and that seems to be what is throwing the error.

Now, using the unbuffered query is supposed to be a bit quicker for large data sets - cool. But how do you avoid what happened to me above?

coopster

1:46 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You also have to fetch all result rows from an unbuffered SQL query, before you can send a new SQL query to MySQL.

mipapage

2:16 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(duck! here comes the rookie}

Thanks coopster.

Okay, so, here goes...

  1. In my mind, it should stay in that while loop until they are all fetched, no?
  2. Can I write an if statement to control things, perhaps on the next query?
  3. Could this actually slow down my script? I mean, having to wait for one query to finish before another one starts?

OT: if I avoid using classes does that mean I won't get to write spaghetti code? [webmasterworld.com]
Added: Crap - just wrote my first class, no looking back now! Now, where's tha pasta aisle?

coopster

3:08 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I believe the PHP mysql_unbuffered_query() [php.net] function is actually calling MySQL's mysql_use_result() [mysql.com] API. There is some really good information on the MySQL C API Function Overview [mysql.com] pages too (scroll way down to the bottom or search for mysql_use_result).

If you feel you need to use this function, by all means do so, just be careful and know what you are doing as you could tie up your processor.

There is good advice in the PHP User Contributed notes from David dated May 17, 2002.

mipapage

3:11 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks coopster, I'm all over it.