Many people are excited about storing json data inside mysql table.
So I created a column type json and tried.
$string = '["BERN", "BERLIN", "AMSTERDAM"]';
$sql = "update posts set tags = :atags where id = :aid";
$st = $db->prepare($sql);
$st->execute(array(
":atags" => $str,
":aid" => $_POST['id']
));
stored value is - ["BERN", "BERLIN", "AMSTERDAM"]
another way:
$arr = json_decode($str);
$st->execute(array(
":atags" => $arr,
":aid" => $_POST['id']
));
stored value is again - ["BERN", "BERLIN", "AMSTERDAM"]
So this is my first question - is it ok that stored value is the same in both cases?
Second - what is the advantage of storing that value inside json comparing to varchar field?
I can search this varchar value as usual:
select * from posts where tags like '%BERLIN%'...
Could someone give me an example - what can I do with json data - and cannot do with string data inside mysql table.
Thanks.