I have a situation where I need to have multiple values stored in my database but they are approx. same type so now I don’t know is it faster to store those values as a String in VARCHAR field in MySQL separated with commas
1,2,3,4,5
and then explode them every them I need them
$values = explode(",", $stringFromDatabase);
where $stringFromDatabase is String from mysql_query + mysql_fetch_array and get them one by one with $values[0], $values[1] and so on
OR
Add another columns for every variable (max. 7 rows) and then call the database for specific row and just get them individually by columns with standard mysql_query + mysql_fetch_array procedure?
So, one column concatenated with commmas or multiple columns? Important to notice, I always need them all (one by one ofcourse) and sorting is not important – so I think that the first option – is the better, faster one?
Its better to have multiple columns. It part of database normalization not to have multivalued columns.
In your case – what if you needed to select the “
3” on from the multivalued1,2,3,4,5? It would be quite challenging. But with multiple columns I can easily doSELECT * FROM Table Where Column3 = 3.