print_r($query) is not a particularly useful method of troubleshooting a problem with your code's interaction with the database library. A given driver may not populate num_rows or row_data when you call foreach($query->result() as $row).
In fact, as is evidenced in the output you posted, it's more likely that the data is stored in result_object, since calling result() with no arguments calls the result_object() method, which populates that property with the results from the driver's _fetch_object() method.
The num_rows property is usually populated only after you've called the num_rows() method. If the property has previously been populated, the num_rows() method will return the value of the property, rather than attempting to either get the number from the driver or count the result_* properties.
You should not be using either the num_rows property or the row_data property in your own code, as they are only intended for the database library's internal use.