Check that payments array isn't empty before performing SQL query. Closes #2019