{"record":{"id":"af88b1260fcc04e4","repo":"phacility/phabricator","slug":"there-are-some-results-left-in-the-result-set","errorCode":null,"errorMessage":"There are some results left in the result set.","messagePattern":"There are some results left in the result set\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnection.php","lineNumber":137,"sourceCode":"    }\n\n    if (!mysql_multi_query(implode(\"\\n;\\n\\n\", $raw_queries), $conn)) {\n      $ex = $this->processResult(false);\n      return array_fill_keys(array_keys($raw_queries), $ex);\n    }\n\n    $processed_all = false;\n    foreach ($raw_queries as $key => $raw_query) {\n      $results[$key] = $this->processResult(@mysql_fetch_result($conn));\n      if (!mysql_more_results($conn)) {\n        $processed_all = true;\n        break;\n      }\n      mysql_next_result($conn);\n    }\n\n    if (!$processed_all) {\n      throw new Exception(\n        pht('There are some results left in the result set.'));\n    }\n\n    return $results;\n  }\n\n  protected function freeResult($result) {\n    mysql_free_result($result);\n  }\n\n  public function supportsParallelQueries() {\n    // fb_parallel_query() doesn't support results with different columns.\n    return false;\n  }\n\n  /**\n   * @phutil-external-symbol function fb_parallel_query\n   */","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnection.php#L119-L155","documentation":"After processing the expected number of statements in a multi-query call, mysql_more_results() still reports pending result sets on the server side — the query string returned more results than the client consumed. The connection state is now inconsistent, so the driver aborts rather than silently dropping data. This is the ext-mysql driver's version of the check (mysqli has an identical one).","triggerScenarios":"Passing several ';'-separated statements in a single queryf()/queryfx() call; calling a stored procedure that returns multiple result sets; a query string built by concatenation accidentally containing an extra statement or trailing semicolon fragment.","commonSituations":"Running hand-written migration SQL that was written as one script but executed as one query; wrapping procedural logic in stored procedures; copy-pasted dump fragments executed through the wrong API.","solutions":["Execute one statement per query call: split scripts into individual queryfx() invocations","If a stored procedure legitimately returns multiple sets, consume every set (loop while more_results) instead of expecting a fixed count","Inspect the exact string being sent — look for stray semicolons or embedded statements from concatenation","Prefer the mysqli driver path for new code; both enforce the same rule"],"exampleFix":"// before: multiple statements in one call\nqueryfx($conn, 'UPDATE a SET x = 1; UPDATE b SET y = 2;');\n\n// after: one statement per call\nqueryfx($conn, 'UPDATE a SET x = 1');\nqueryfx($conn, 'UPDATE b SET y = 2');","handlingStrategy":"validation","validationCode":"// Before executing, assert one statement per call:\nfunction assert_single_statement($raw_query) {\n  if (preg_match('/;\\s*\\S/', trim($raw_query))) {\n    throw new Exception('Split multi-statement SQL into separate calls.');\n  }\n  return $raw_query;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Send exactly one statement per queryf()/queryfx() call; split migration scripts programmatically","Do not route stored procedures returning multiple sets through the fixed-count multi-query API","Inspect concatenated SQL for stray semicolons before executing it"],"tags":["mysql","multi-statement","result-set","protocol","ext-mysql"],"backgroundTag":"unconsumed-query-results","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}