Answers for "mysql commands out of sync"

PHP
0

mysql commands out of sync

<?php
    
/**
 *	Free all resultsets from $dbCon. Object Oriented
 * Originally from https://falseisnotnull.wordpress.com/2013/06/02/mariadbmysql-commands-out-of-sync-error/
 *	@param		mysqli		$dbCon	mysqli object.
 *	@return		void
 */
function free_all_results(mysqli $dbCon)
{
    do {
        if ($res = $dbCon->store_result()) {
            $res->fetch_all(MYSQLI_ASSOC);
            $res->free();
        }
    } while ($dbCon->more_results() && $dbCon->next_result());
}
    

/**
 * Free all resultsets from $dbCon. Procedural
 * @param mysqli $dbCon mysqli object.
 * @return        void
 */
function free_all_results(mysqli $dbCon): void {
	do {
		if ($res = mysqli_store_result($dbCon)) {
			// $res->fetch_all(MYSQLI_ASSOC);
			mysqli_fetch_all($res, MYSQLI_ASSOC);
			mysqli_free_result($res);

		}
	} while (mysqli_more_results($dbCon) && mysqli_next_result($dbCon));
}






?>
Posted by: Guest on July-17-2021

Browse Popular Code Answers by Language