Medoo
Medoo copied to clipboard
How to use mysql json function in where clause?
So I have query which required us to use Mysql json function such JSON_OVERLAP()
I want to use it alongside other array keys in where clause in select function. Is it possible?
Using Medoo::raw() and building query is not possible for us due to the architecture that we chose atm.
At the end we want to build query such as
select * from table_name
where <conditions_from_other_places_in_where_array> and JSON_OVERLAPS('<some_col>', <array_from_request>)
i need this too.
Now we can make a where in two way
$db->select('table',[], Medoo::raw('WHERE ALL MY CONDITIONS'));
or this way:
$db->select('table',[], [ 'myfield' => 1 ]);
it would be very useful to do something hybrid like that
$db->select('table',[], [ 'myfield' => 1, Medoo::raw('myfunction(MYFIELD2) = true') ]);
in the (1.7.10) it will be translated with a '0' = myfunction(MYFIELD2) = true (because he wants a column name there) it could be fixed in dataImplode method of medoo extending that class but that's not maintainable.
one workaround for this which works is to use the conditions like this
php
$data = $database->select("products",*, [
"price[>]" => 1000,
"id" => Medoo::raw('<id> AND JSON_OVERLAPS(<categories>, "[100,200,300]")')
]);