Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    463
    Plugin Contributions
    0

    Default Fetch next row from database query

    Why does this simple function not work in my code?
    Code:
    class queryFactoryResult {
    ...
      function FetchObject() {
        return @mysqli_fetch_object($this->resource);
      }
    ...
    Usage:
    Code:
        $the_query = $db->Execute($query);
    ... 
        if ($the_query->RecordCount() > 0) {
          $atom = $the_query->FetchObject();
          $orders_id[$loop] = $atom->order_id;
    ...
          $loop++;
    ...

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Fetch next row from database query

    I have no idea where that code came from, nor the ideas behind it.

    The way the Zen Cart database query infrastructure works is this:

    Code:
    $sql = "select * from " . TABLE_TABLENAME . " WHERE field='value'";
    $result = $db->Execute($sql);
    
    while (!$result->EOF) {
    
      $my_variable = $result->fields['fieldname'];
    // and/or do something with that $my_variable value
    
    
      $result->MoveNext(); // to tell it to advance to the next record
    } // this loops back to the "while" loop, repeatedly, until the EOF is triggered when all the results have been returned.
    In v155 the code is even simpler, but you specified v154 so I gave you the old syntax.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    463
    Plugin Contributions
    0

    Default Re: Fetch next row from database query

    The code is from /includes/classes/db/sql/mysql/queryFactory - a deprecated part?

  4. #4
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    463
    Plugin Contributions
    0

    Default Re: Fetch next row from database query

    I.e. I added the FetchObject-code with the same syntax (?) as RecordCount().

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Fetch next row from database query

    I explained the correct usage and syntax above.
    There's no need to change the query_factory.php code.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    463
    Plugin Contributions
    0

    Default Re: Fetch next row from database query

    Fair enough. Is there a way to reset a query to start, without redoing it - ex. $result->MoveTop()

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Fetch next row from database query

    Not reliably before v155.

    Why exactly are you wanting to rewind to start?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    463
    Plugin Contributions
    0

    Default Re: Fetch next row from database query

    A little bit messed up - will start thinking straight after aligning with ZenCart db-procedures.

  9. #9
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Fetch next row from database query

    The syntax is definitely much easier after upgrading to v155:

    Code:
    $sql = "foo";
    $result = $db->Execute($sql);
    
    foreach ($result as $row) {
    
      echo $row['fieldname'];
    
    }
    And also supports proper Iterator and Countable actions such as reset(), count(), as well as Move(0) and more.

    ... but you need at least v1.5.5 to have these available.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  10. #10
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    463
    Plugin Contributions
    0

    Default Re: Fetch next row from database query

    Ok, Thanks.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v154 How to Get Count from Last Delete Query - Row Affected?
    By kwright in forum General Questions
    Replies: 3
    Last Post: 21 Feb 2016, 06:16 PM
  2. Fetch user email address from database
    By hoehnt in forum General Questions
    Replies: 6
    Last Post: 21 Dec 2009, 08:45 PM
  3. Fetch blocks of text from other URLs?
    By sjk1000 in forum General Questions
    Replies: 8
    Last Post: 3 Oct 2008, 04:05 AM
  4. ZenCart database setup error -12263 and Could not fetch schema tables
    By Xulayman in forum Installing on a Windows Server
    Replies: 4
    Last Post: 21 Aug 2007, 07:11 AM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR