updated to work without using fetch_all

fetch_all is only available with the mysql native driver, which is not available on all systems.  Also, fetch_all uses more memory than iterating over the result set.