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 trialTed Sumner
Courses Plus Student 17,967 Pointsdatabase versus array
When is it appropriate to use a database versus an array for data storage?
Ted Sumner
Courses Plus Student 17,967 PointsNo, I mean a PHP array.
3 Answers
Dave McFarland
Treehouse TeacherA database is for permanently (or at least semi-permanently) storing information that you later want to retrieve or update. The data is stored in a database management system like MySQL and you use SQL to manage that data.
An array is a data-storage mechanism, but it's volatile, in that you create arrays within programs for handling lists of data and after the program completes, the array disappears from memory. You use arrays for storing multiple related pieces of data as described in Introducing Arrays.
The StackOverflow article you point to, is about using arrays within forms for collections of form data. This is very common. It is only as secure as you make it. You need to make sure data that's sent via a form is "filtered." You can watch the PDO Security and the Filter Input, Escape Output videos for more about database security around data input and output.
Saskia Lund
5,673 PointsHm you can save arrays in a database and make the changes "visible" for later reference so to say.
When using an array that was once declared somewhere in a php file, and later in the coding you'd add some kind of objects to it that are merely added while the program runs..
So I guess databases saving should be used when you need to save larger "arrays" of related values that also should be available for later reference and also be available to other programs.
Ted Sumner
Courses Plus Student 17,967 PointsYou can add user input into an array in PHP as described here. I wonder if there are security issues or something else.
Saskia Lund
5,673 PointsSaskia Lund
5,673 PointsYou mean an array in terms of JavaScipt array?