If you are STILL getting this error, even after freeing your results:
Internal SQL Bug: 2014, Commands out of sync; you can't run this command now
You may have a stored procedure in your query. A procedure can return more than one result set, and it will always return one extra empty result set that carries some meta information on the procedure call itself, especially error information. ( source: https://bugs.mysql.com/bug.php?id=71044 )
While calling single procedures, with one SELECT in them, using mysqli->query("CALL `stored_procedure`();"), I had to do the following to make it work between two calls:
<?php
$result->free();
$mysqli->next_result();
?>
It has no negative impact if you are not calling a stored procedure.