Is there IN() function in Medoo?

253 Views Asked by At

Lets say I have this piece of code:

$this->database->debug()->select(
            'client',
            [
                'id',
                'name',
                'phone',
                'email',
                'address'
            ],
            Medoo::raw(
                'WHERE `id` IN(:clientIds)',
                [
                    ':clientIds' => $clientIDs
                ]
            )
        );

It gives me this error:

Notice: Undefined index: array in vendor\catfan\medoo\src\Medoo.php on line 519
Call Stack
#   Time    Memory  Function    Location
1   0.4014  404880  {main}( )   ...\test.php:0
2   0.4269  1080712 Writers\InvoicesWriter->Write( )    ...\test.php:9
3   0.4430  1136296 Writers\InvoicesWriter->getClientInfo( )    ...\InvoicesWriter.php:18
4   0.4430  1136752 Medoo\Medoo->select( )  ...\InvoicesWriter.php:83
5   0.4431  1136816 Medoo\Medoo->selectContext( )   ...\Medoo.php:1365
6   0.4433  1137496 Medoo\Medoo->whereClause( ) ...\Medoo.php:1075
7   0.4433  1137496 Medoo\Medoo->buildRaw( )    ...\Medoo.php:983
8   0.4434  1137496 Medoo\Medoo->typeMap( ) ...\Medoo.php:471

So, I'm guessing it doesn't support it then? If not, how do you think I should use IN() safely?

2

There are 2 best solutions below

0
dydx On

Looks like there is:

$database->select("account", "user_name", [
    "OR" => [
        "user_id" => [2, 123, 234, 54],
        "email" => ["[email protected]", "[email protected]", "[email protected]"]
    ]
]);
// WHERE
// user_id IN (2,123,234,54) OR
// email IN ('[email protected]','[email protected]','[email protected]')

But I don't think you can use it with the raw object.

0
Blessed Jason Mwanza On

YES. * And here is how its done*

$database->select("table_name", "column_name", 
    [
        "Value" => [option1, option2, option3, e.t.c]
  ]
);
  • example
$database->select("users", "user_id", 
    [
      "age" => [12, 15, 18, 14]
    ]
);

The example above explains to >> "SELECT `user_id` FROM `users` WHERE `age` IN(12, 15, 18, 14)"

You can find more examples here