Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-14354

$db->sql_affectedrows does not work correctly with cached queries

    Details

      Description

      When a query result is loaded from cache, subsequent calls to $db->sql_affectedrows() will return information about the last query that had actually been run, which may be a completely different query.

      Example:

      $sql = 'SELECT * FROM phpbb_users WHERE 1';
      $result = $db->sql_query($sql); // No caching here
       
      $sql = 'SELECT * FROM phpbb_groups WHERE 1';
      $result = $db->sql_query($sql, 30);
      $found_groups = $db->sql_affectedrows();
      

      Running this code twice in a row within 30 seconds of each other will return different values for $found_rows. On the first run, it will contain the number of groups as intended, on the second run it will return the number of users instead.

      If it is intended that sql_affectedrows should only be used when running changing queries, that is fine, but should possibly be documented in the description of the driver interface (I don't know how the function behaves on database backends other than Mysql/MariaDB), otherwise this should probably be changed to returning the number of cached rows instead, if the last run query was found in the cache.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              gn#36 gn#36
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: