1<?php
2
3/**
4 * Free all resultsets from $dbCon. Object Oriented
5 * Originally from https://falseisnotnull.wordpress.com/2013/06/02/mariadbmysql-commands-out-of-sync-error/
6 * @param mysqli $dbCon mysqli object.
7 * @return void
8 */
9function free_all_results(mysqli $dbCon)
10{
11 do {
12 if ($res = $dbCon->store_result()) {
13 $res->fetch_all(MYSQLI_ASSOC);
14 $res->free();
15 }
16 } while ($dbCon->more_results() && $dbCon->next_result());
17}
18
19
20/**
21 * Free all resultsets from $dbCon. Procedural
22 * @param mysqli $dbCon mysqli object.
23 * @return void
24 */
25function free_all_results(mysqli $dbCon): void {
26 do {
27 if ($res = mysqli_store_result($dbCon)) {
28 // $res->fetch_all(MYSQLI_ASSOC);
29 mysqli_fetch_all($res, MYSQLI_ASSOC);
30 mysqli_free_result($res);
31
32 }
33 } while (mysqli_more_results($dbCon) && mysqli_next_result($dbCon));
34}
35
36
37
38
39
40
41?>