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!

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

General Discussion

Personal Projects Please

I'm working through Randy's PHP sessions and coding right along with the video. After I'm done I'm going to continue to build on it and launch a store. Has anyone else done this? Please share live projects inspired by badge completions.

Thank You.

3 Answers

Thank You. Is there a rule or magic number where your store should move from an array to a database? If so is that covered in a later lesson?



James Barnett
James Barnett
39,199 Points

Matthew McLennan - Array's forget, they don't write anything to disk.

When your PHP process ends all the data in an array goes up in smoke. Databases store data in special kinds of files so you can access it later.

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

Hey Matthew,

We'll be covering how to store the products in a database in a future tutorial. I'd personally say stick with an array as long as you can. Adding a database adds complexity and overhead that can slow down the site, limit your hosting options, make it hard to back up data, make deploying data to production trickier, etc. I have a number of smaller sites that run on PHP only and store structured data in an array like the Shirts 4 Mike site.

You'd want to switch to a database when you reach any of these points:

  • If non-technical users need to change the data
  • If the number of products grows to a point where the making changes to the array are too hard to make (what counts as "too hard" is completely relative to your threshold for pain :-) )
  • If you need to store data that relates products to each other or to other types of data (companies, categories, etc.)
  • If you need different data in multiple environments (like development, test, stage, and production environments)

Of course, for many sites and applications you'll have one of these conditions in place right at the start. You'll need to start with a database a lot of the time. But I think people are too quick to jump to a database for a simple site like the Shirts 4 Mike site, when an array would probably serve them better.

Thank you. Randy, can you share some of your sites?