XF 2.2 json or serialize

Robert9

Well-known member
I want to save an array.

seralize does
a:18:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;i:4;i:5;i:5;i:6;i:6;i:7;i:7;i:8;i:8;i:9;i:9;i:10;i:10;i:11;i:11;i:12;i:12;i:13;i:13;i:14;i:14;i:15;i:15;i:16;i:16;i:17;i:17;i:18;}

json_encode does
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]

When i want to save the longer version, please?

The only thing i could miss in the json could be to add a comma at the begin and end, if i want to do a search on this field.
[,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,]

Now i can do "where field like %x,%

without the two "," you need to ask where field like x,% or %,x,% or %,x
 
You can also use json colum in the xenforo if you are using mysql version.greater then 5.7.8 which xf supports too and you can always apply mysql json search methods too on it if you want.
 
You shouldn't execute MySQL queries on either json or serialized fields either way. They're for storage, not querying. If you're storing an unordered list of integers and need to query a specific value, store them as comma separated list and use FIND_IN_SET, or store them in a relational table to map the 1:N relation so you can run well-indexed queries if you require complex or frequent queries on the table.
 
Back
Top Bottom