I want to store array [3,9,21] in database (mySQL).Other than saving the values of array, I want to save the whole array in the database. Is it possible?
1 Answer
If you are using MySQL 5.7+ you can; it introduced a JSON data type https://dev.mysql.com/doc/refman/5.7/en/json.html
A quick read about the changes: http://lornajane.net/posts/2016/mysql-5-7-json-features
PS -- I'm a fan of the comment above -- storing values as separate rows instead of as arrays is a better option
2 Comments
tadman
If you need to reference these values in a
JOIN or a WHERE clause, yes, you absolutely do need to break them out into a proper relational structure. That's not always the case, and sometimes serializing as JSON is actually more convenient.Amir Raminfar
You should store each item as a row. Keep your data organized will be much cleaner.
serializemethod.