Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


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?

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