Skip to content

MysqliUnbufferedResultBlocksNextQuery ​

warning native on by default

Group: Probable bugs

An unbuffered mysqli result can block further queries on the same connection. Consume or free it before issuing another query.

Example ​

php
<?php
$db=new mysqli();$r=$db->query("SELECT id FROM users",MYSQLI_USE_RESULT);$db->query("SELECT 1");

Reported:

  • line 2: Consume or free the unbuffered result before another query.

Detection ​

  • Resolved mysqli::query uses MYSQLI_USE_RESULT; same connection issues next query before returned result is freed or fully consumed by a proven exhaustion loop. Require direct result ownership and no intervening unknown escape.
  • The unbuffered query must be a known literal result-producing SELECT, SHOW, DESCRIBE or EXPLAIN statement. Mutating statements that return only a success boolean, unknown SQL, and unsupported statement kinds do not establish an outstanding result set.
  • The next query is the statement directly after the unbuffered assignment, and nothing in that statement may touch the result variable before the query runs (including inside the query's own arguments): a method call on it, passing it as an argument or capturing it may consume or free the result first, so no report. Overwriting the variable with a plain assignment is not such a use, and uses positioned after the query do not help.
  • Resolve builtin functions, classes, constants and methods; user-defined lookalikes are excluded. Follow only bounded local proof in one lexical scope.
  • Emit one finding per violating operation, not per supporting evidence statement. When the proof is inconclusive, nothing is reported.

Exceptions (no report) ​

  • Do not report unresolved or shadowed builtin names, unknown values, or incomplete receiver/type provenance. Unknown calls, aliases escaping, and intervening writes invalidate local proof. Similar code outside the stated detection contract is not a finding.
  • Both standard suppression forms suppress this native ID.

Fix ​

None. Choosing a repair requires intent or additional runtime information.

PHP versions ​

Available throughout supported PHP 5.3–8.5 where the referenced builtin/extension is available. Respect syntax/version-specific receiver contracts; unavailable APIs are not this rule’s concern.

Configure ​

In custos.json:

json
{
  "rules": {
    "MysqliUnbufferedResultBlocksNextQuery": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore MysqliUnbufferedResultBlocksNextQuery

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.