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
Kristian Terziev
28,449 PointsArray in database
Hello,
Is there a way to upload an array to myslq database.
2 Answers
Jeremy Hayden
1,740 PointsKritian,
Usually if an array is important enough to store in mysql, you are going to also want to be able to manipulate the data stored. Like sort it, search it, modify it... Ect
I would suggest not storing it as an array, but break it down into meaningful tables.
You can easily loop thru your arrays and send over data to mysql.
Then when you want the data back, just rebuild your arrays the same way.
Sjors Theuns
6,091 PointsYes, this is possible. You can take a look at the following PHP functions:
serialize (http://php.net/manual/en/function.serialize.php)
unserialize (http://php.net/manual/en/function.unserialize.php)
Keep in mind that it is not always the best solution to store an array in the database, but sometimes it's necessary.
Hope this helps.
Kristian Terziev
28,449 PointsKristian Terziev
28,449 PointsThanks you both for the answers. I realy think it is better if i split my array into columns as Jeremy suggested.