Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-14354

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Minor Minor
    • None
    • 3.1.6
    • None
    • PHP 5.5.9, MySQL 5.5.46 (Ubuntu 14.04 / Linux Mint 17.3)

      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.

            Marc Marc
            gn#36 gn#36
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: