Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Heidi Brebels
Heidi Brebels
21,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

1 Answer

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

Hey Heidi,

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?

Heidi Brebels
Heidi Brebels
21,856 Points

Hello Randy,

Thank you so much for your answer! It indeed makes sense. I've implemented it this way and it works like a charm!

You rule! :) Regards Heidi