Page 1 of 1

mysql_unbuffered_query()

Posted: Wed Aug 23, 2006 10:13 am
by Oren
mysql_unbuffered_query()
First time I hear about this function. I've never seen anyone using this function and after reading the manual it seems to me that it has great advantages, are there any disadvantages/reasons as to why no one is using it (at least I've never seen anyone :P).

Posted: Wed Aug 23, 2006 10:40 am
by feyd
take a look at the user comments.

Posted: Wed Aug 23, 2006 11:26 am
by Ollie Saunders
This doesn't seem to be implemented in mysqli. Am I right?

Posted: Wed Aug 23, 2006 2:57 pm
by Oren
feyd wrote:take a look at the user comments.
If you are talking about the fact that you can't use mysql_num_rows(), I've already read that in the manual and that's not a problem.
If you are talking about something else, please tell me what exactly.

I see no reason why not using it instead of mysql_query(), but since I've never seen anyone using it, I assume there must be a good reason after all.
Does anyone know what this reason might be?

Thanks.

Posted: Wed Aug 23, 2006 3:05 pm
by Chris Corbyn
~Oren... it basically only works while the connection to the DB is still alive. If you disconnect before processing the result, you lost the ability to do so. Apart from that it seems fairly sensible to use for large resultsets.

Posted: Wed Aug 23, 2006 3:19 pm
by Oren
d11wtq wrote:Apart from that it seems fairly sensible to use for large resultsets.
Then why it isn't used at all (I think)?
Since when you close the connection before you finish to work with the database? :?

Posted: Wed Aug 23, 2006 3:28 pm
by Chris Corbyn
Oren wrote:
d11wtq wrote:Apart from that it seems fairly sensible to use for large resultsets.
Then why it isn't used at all (I think)?
Since when you close the connection before you finish to work with the database? :?
You may use a DB class which opens a connection while it runs a query then sends you the result and closes the connection. You'd then be working with a buffered result after the connection is closed which would be fine, but with mysql_unbuffered_query() it just wouldn't work. I'm not saying you should use it, I'm just providing an example :) I'd probably make use of this since like you say, a DB connection will usually remain open for the duration of the page request, or at least until you've finished using the DB.

Posted: Thu Aug 24, 2006 3:11 am
by Jenk
It may be a good idea to only use mysql_pconnect and mysql_close if you are going to use unbuffered query.

Posted: Thu Aug 24, 2006 3:37 am
by Ollie Saunders
Jenk wrote:It may be a good idea to only use mysql_pconnect and mysql_close if you are going to use unbuffered query.
Yep this is a well known performance booster.
You may use a DB class which opens a connection while it runs a query then sends you the result and closes the connection.
Change to use a destructor to close the connection.

Posted: Thu Aug 24, 2006 4:16 am
by Oren
ole wrote:Change to use a destructor to close the connection.
Never done it in a different way :P

Posted: Thu Aug 24, 2006 4:19 am
by Jenk
you 'should' create a close() method on your DB class incase you ever do want your script to close the connect prior to script termination.

Posted: Thu Aug 24, 2006 9:26 am
by feyd
Last I saw/checked, pconnect wasn't much of a speed booster anymore. It's benefits went south after PHP 3, if memory serves.

Posted: Thu Aug 24, 2006 9:39 am
by Oren
<off-topic>"That's feyd, not Feyd, not fyed; just feyd. Pronounced fade. ", good to know... each time I used your name I wasn't sure since I had seen others write it as "Feyd", but I just write the names exactly as they appear in the user's profile :P </off-topic>

Posted: Thu Aug 24, 2006 9:43 am
by Jenk
feyd wrote:Last I saw/checked, pconnect wasn't much of a speed booster anymore. It's benefits went south after PHP 3, if memory serves.
Is that true for mysql_pconnect on it's own, or in conjunction with mysql_unbuffered_query()? I'm unable to test atm.

Posted: Thu Aug 24, 2006 9:54 am
by feyd
Jenk wrote:Is that true for mysql_pconnect on it's own, or in conjunction with mysql_unbuffered_query()? I'm unable to test atm.
I believe it's the use of pconnect at all, mysql_unbuffered_query() or not.