I think this Stack Overflow question is related to your query: [PHP Commands Out of Sync error][1] It's because results are not completely fetched before another call. PHP docs has a solution read this too: http://www.php.net/manual/en/mysqli.query.php#102904 [1]: https://stackoverflow.com/a/14561774/3359432