0

i am using laravel for my project. i performed a query. it works fine in localhost. but started giving this error after i have uploaded it on the server. here is my query below

$result = Card::SELECT('id','name','unique_id','nid','geo_union_id','house_category','house_name','vata_list','mobile','profession','family_members')
    ->whereraw("JSON_CONTAINS(vata_list,'[$request->id]')")
    ->where('geo_union_id','=',$union)
            ->get();

and this is the error i am having in live server

Syntax error or access violation: 1305 FUNCTION mydb.JSON_CONTAINS does not exist

2 Answers2

1

Just make sure that MySQL version in your local and server are the same. Since json_contains was introduced in later versions of MySQL (5.7 think so).

sn n
  • 319
  • 1
  • 5
  • 19
  • yeah. mine is less than 5.7. Does it have an alternative function? – Abidus Sattar Aziz May 03 '20 at 04:23
  • You need to write a custom function in that case. Possible duplicate of https://stackoverflow.com/questions/37816269/how-to-get-values-from-mysql5-6-column-if-that-contains-json-document-as-strin – sn n May 03 '20 at 05:59
  • json extract in that example could be possible if i had jsob objects, but in this case i have arrays [1,3,7] – Abidus Sattar Aziz May 03 '20 at 06:56
0

I think the error is you are calling whereraw(), instead you need to be calling whereRaw() (notice the uppercase R).

Goater
  • 56
  • 1
  • 4