SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_query() vs mysql_unbuffered_query()

    this question is in reference to a PHP function, but its based on mysql. please move it if it is in the wrong forum.

    what is the difference between mysql_query() and mysql_unbuffered_query()?

    the php manual does not make sense to me.

    also is there much difference between the normal and the unbuffered version, in regards to speed and memory usage?

    thanks

  2. #2
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you're doing a query, usually the complete query will be done, all data (=result of the query) is sent to memory and only if all data is fetched the complete data will be made available for further use.
    When using an unbuffered query, the data is not read into memory but becomes immediately available, eg. you already can work with the first (resulting) rows while the server still works on the rest of the query.
    This comes in particularily handy of you're working with a large set of data.
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your response frezno,

    so with smaller sets of data, i would not see much of a performance gain?

    i noticed with the unbuffered query, you are sacrificing some PHP SQL features. i was unable to get mysql_num_rows() to work, for example. also mysql_ping() supposedly doesn't work, there are probably more.

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    let me try to rephrase frezno's description:

    with mysql_query(), the function call does not return until the query is done processing and the mysql server has returned all of the rows found (i.e., php is holding ALL of the rows in memory for your use). that is why you can use mysql_num_rows(): PHP has already retrieved all of the rows and was able to count them.

    with mysql_unbuffered_query(), the function call returns as soon as the mysql server starts execution. you are then free to use mysql_fetch_row() to start pulling back rows from the mysql server. mysql_fetch_row() will wait until the mysql server has another row ready for php, then return that row. since PHP has not pulled back ALL of the rows and mysql is still (potentially) finding rows even after you start retrieving rows, you won't be able to use mysql_num_rows().

  5. #5
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    makes perfect sense now, thank you


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •