Converts mysql query result array (flat) to nested (multi-dimensional) object.