Cannot read property 0 of undefined simply means is that you are trying to access the property 0 of an undefined variable. You most likely have rows variable undefined. Make sure that you have that variable properly set in your table, personally I would recommend you to print out stuff until you get some clues of where the problem may be in. Correct me if I am wrong.
btw, is this code simplified? you should be passing a value for the db to substitute in for the ?
undefined could be consistent with my guess above. if you’re really closing the connection before the query gets processed, maybe it’s the db’s behavior to pass rows = [] to that callback