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

MarvinX's avatar

Check if database supports json

Is there an easy way to determine wherever the database supports json? I am using the whereJsonCointains model method but as I read in the docs, only some database types support json operations. My current approach is to just add a try-block around the query and catch the exception but this seems a bit dirty to me.

0 likes
4 replies
Tray2's avatar

I advise you to really rethink the use of a json column in your database. It will make most CRUD operations much harder and it will also make your system a bit slower since your really can't use indexes.

The whereJsonContains should only be used on json columns. You should never use it on a non-json column. So you don't need any try catch if you do it properly.

MarvinX's avatar

@Tray2 Unfortunately I use a third party library which stores the data in json format either in a text or a json column. I changed whereJsonContains to the native where which uses the SQL JSON_EXTRACT() function which is sufficient for my use case to support SQLite databases.

jlrdw's avatar

I agree, storing json is not good. I might store a simple checkbox array as json.

But as far as finding out the support of a Json column, each database will have the documentation on types it supports.

For example: https://dev.mysql.com/doc/refman/8.0/en/json.html

Of course if you have an earlier version of MySql, then check that versions documentation.

MarvinX's avatar

@jlrdw Manually reading all the docs and comparing the current driver to a custom mapping table is not really an option as I would be laborious to maintain

Please or to participate in this conversation.