Is there any proper way to escape array without brackets in MeekroDB?

183 Views Asked by At

I want to write query like this in MeekroDB:

SELECT * FROM `tablename` WHERE `id` IN (3,1,2) ORDER BY FIELD (`id`,3,1,2)

And I expect it to work like this in meekro:

$possible_ids = array(1,2,3);
DB::query('SELECT * FROM `tablename` WHERE `id` IN %ld0 ORDER BY FIELD (`id`,%ld0)', $possible_ids);

But it get this:

SELECT * FROM `tablename` WHERE `id` IN (3,1,2) ORDER BY FIELD (`id`,(3,1,2))

Is there any way to avoid this brackets here?

1

There are 1 best solutions below

1
On

Try this one :

$possible_ids = implode(',', array(1, 2, 3));
//echo "SELECT * FROM `tablename` WHERE `id` IN %ld0 ORDER BY FIELD (`id`,%ld0)', $possible_ids";

DB::query('SELECT * FROM `tablename` WHERE `id` IN %ld0 ORDER BY FIELD (`id`,%ld0)', $possible_ids);

also you can check with echo query. try it's working fine.