0

So i wanted to save some tags data to the database from the UI form,

Tags: ["male","female","kids"]

I tried everything like but it saves as a string, ialso tried checking if i can alter the data type to array in mysql, or json but i got this

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'JSON(255) NOT NULL' at line 1

I also tried json_encode and json_decode() but still no head so please what can i do?

Shadow
  • 33,525
  • 10
  • 51
  • 64
udemethegrtman
  • 107
  • 2
  • 14
  • Pls share what you have tried! Based on an error message only it is a bit difficult to figure out what may have gone wrong. – Shadow Jul 21 '16 at 23:24

2 Answers2

2

There isn't any data type as JSON or Array in DB.
What you can do is use the tags field as TEXT as told by @Rick James and then encode your input as json by using json_encode() method before inserting and decode it after retrieving the data from DB by using json_decode() method.

JSON is basically a minimal, readable format for structuring data. Which means it can be considered as a String.

Here is a good post about JSON, in case you need. What is JSON?

Community
  • 1
  • 1
jaysingkar
  • 4,315
  • 1
  • 18
  • 26
0

There is no datatype called JSON. Instead use TEXT without the (255).

Rick James
  • 135,179
  • 13
  • 127
  • 222