SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: Rows with mysql_unbuffered_query()?

  1. #1
    SitePoint Zealot DraginX's Avatar
    Join Date
    Mar 2003
    Location
    US
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rows with mysql_unbuffered_query()?

    I need help finding rows in a atable using mysql_unbuffered_query()...

    PHP Code:
    $select2 mysql_unbuffered_query("
    SELECT id FROM `accounts`
    WHERE `email` = '" 
    $email "' || `name` = '" $name "'
    "
    );
    if(!
    mysql_fetch_row($select2)){
    quit('Someone already has your email address or character name!');

    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /register.php on line 39
    Someone already has your email address or character name!

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_unbuffered_query("
    SELECT id FROM `accounts`
    WHERE `email` = '" . $email . "' || `name` = '" . $name . "'
    ") or die(mysql_error());

    I'm guessing it doesn't like the ||, try using OR instead.

  3. #3
    SitePoint Zealot DraginX's Avatar
    Join Date
    Mar 2003
    Location
    US
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still doesn't work

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then i'd put the query in a var and echo it to make sure it's what you expect.
    Like :
    $sql = "SELECT id FROM accounts
    WHERE email = '$email' OR name = '$name'";
    echo $sql;
    $select2 = mysql_unbuffered_query($sql) or die(mysql_error());

    I removed the backquotes as that's a phpMyAdmin'ism, also add an or die(mysql_error()) to the mysql_connect()

  5. #5
    SitePoint Zealot DraginX's Avatar
    Join Date
    Mar 2003
    Location
    US
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing good man

  6. #6
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,458
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    DraginX, why an unbuffered query? i've never used that (in fact, i've never called mysql from php, but let's not go into that), but the way i read the description of that function, its purpose is to allow you to start processing a large result set before mysql has finished producing it all

    how large can your result set be? you have thousands of rows with the same email and name???
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Member
    Join Date
    Apr 2012
    Location
    Michigan, United States
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unbuffered queries are more efficient. The way a standard query works, the script blocks until the mysql thread has read ALL the data from the query into memory. Then the script resumes.

    With an unbuffered query the script continues while the mysql thread runs in the background. One can continue doing other tasks in the script while it builds, or get straight to work on the data as it comes in. The memory saving occurs where a result with 100,000 rows in standard query requires the memory of 100,000 records. But processing the same unbuffered query may only need 20,000 rows buffered at any time, and the script will complete in half the time because it can continue running while the data is received.

    The problem is not emphasized but it is stated on the documentation. only 1 query can be run at a time.

    //do mysql_connection
    //grab needed data in background
    $settings = mysql_unbuffered_query("SELECT * FROM `settings`;");

    //load local configurations
    $local_dir = dirname(__file__);
    include('.....');

    while($setting = mysql_fetch_assoc($settings)){
    ...
    }

    This script can load the database settings in the background while doing disk-access includes, but if any include run ANY kind of of query, $settings, while still being a mysql_resource_2, will be invalid result resource. An unbuffered query must be processed before any other mysql command is used or the [un]buffered data is discarded.

    try it:
    $result_1 = mysql_unbuffered_query();
    /// some code
    while($row = mysql_fetch_assoc($result_1))
    ...
    $result_2 = mysql_unbuffered_query();
    /// all works fine

    and

    $result_1 = mysql_unbuffered_query();
    $result_2 = mysql_unbuffered_query();
    while($row = mysql_fetch_assoc($result_1))
    INVALID

  8. #8
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,458
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    congrats, ppostma1, this thread is over eight years old

    we can assume the original poster no longer cares, eh
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    Just Blow it! bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    6,701
    Mentioned
    54 Post(s)
    Tagged
    1 Thread(s)
    Holy rising of the dead, batman! THREAD CLOSED
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

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
  •