Better SQL num_rows, fix undefined errors, add DATE_FORMAT support