“Commands out of sync;” fixed!

Can’t call a second stored procedure without reconnecting? The strangest thing, php adds one additional result for every result set returned by stored procedures. Here’s a quick fix for the problem.

function mysqli_flush($conn) {
    while(mysqli_more_results($conn)) {
        if(mysqli_next_result($conn)) {
            $result = mysqli_use_result($conn);
            mysql_free_result($result);
        }
    }
}

Use it when you are done with the results and viola! You can now call another stored procedure.

Posted in php/mysql | Tagged , | Leave a comment