Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Samer_J's avatar

Query JSON column on MariaDB?

My webhost's MySQL version is 10.0.32-MariaDB. Whenever I try to query a JSON column like so:

where('data->model', $reply->id)

I get the following error:

Syntax error or access violation: 1064 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 '>'$."model"

This is because my webhost's MySQL version apparently doesn't support JSON column types. (query works on my Homestead but not on my webhost)

How else am I meant to query a JSON column? Is changing my MySQL version the only option I have? (not even sure if that's possible with my shared hosting)

0 likes
6 replies
Samer_J's avatar

@tisuchi I'm trying to query a JSON column. This is an example of what my data column contains:

{"model":14,"notifying":2,"message":"<b>EGN_Gaming<\/b> liked your post in <b>Introduce Yourself!<\/b>.","action":"https:\/\/egn-gaming.com\/forums\/reply\/14"}

I'm trying to query "model" by using data->model which is the correct syntax for JSON where clauses:

https://laravel.com/docs/5.4/queries#json-where-clauses

However my issue is that the MySQL version I'm using doesn't support that syntax, so I'm looking for an alternative solution.

Drfraker's avatar

According to the MariaDb website, JSON columns are not available unit version 10.2. It appears that your version is below that. Is it possible that is the problem? https://mariadb.com/

Samer_J's avatar

@Drfraker Yes that's the problem. I'm just wondering if there are any alternatives or if the only solution is to update my MySQL version.

dkuzmenchuk's avatar

You can get access to json column using 'whereRaw' method and supported JSON functions.

Smth like

whereRaw('JSON_EXTRACT(`data`, \'$.model\') = ' . $reply->id)

Please or to participate in this conversation.