Welcome to the Treehouse Community
Looking to learn something new?
Heidi Brebels21,856 Points
return value of function with MySQL
When connecting to a MySQL database in your model function, I'm wondering what kind of return type you would give back to the controller?
In Mike's shirts, we return an Array. If I get my data from MySQL, would I then also put all the data I need in an array and return that array to the controller, who can then loop through the data array? Or do I return the mysqli_query result and then loop through this data result with another mysqli function in the controller?
What would be the best MVC/performance practice?
Thanks! Regards Heidi
Randy HoytTreehouse Guest Teacher
You want to return the same array. One of the benefits of separating concerns into MVC like we have done is that you can change something major in the model (like switching from an array to a database) without having to change anything in the controller or the view code.
Does that make sense?