1

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?

dydx
  • 157
  • 15
  • 2
    If you want to use `IN()` you'll need to add as many placeholders as array items. It's easier to just use the builtin [where](https://medoo.in/api/where). – Álvaro González May 03 '20 at 15:51
  • There is [support for `IN` in the source](https://github.com/catfan/Medoo/blob/master/src/Medoo.php#L800), which seems to mirror what @ÁlvaroGonzález says above. – Jared Farrish May 03 '20 at 15:53

2 Answers2

1

Looks like there is:

$database->select("account", "user_name", [
    "OR" => [
        "user_id" => [2, 123, 234, 54],
        "email" => ["foo@bar.com", "cat@dog.com", "admin@medoo.in"]
    ]
]);
// WHERE
// user_id IN (2,123,234,54) OR
// email IN ('foo@bar.com','cat@dog.com','admin@medoo.in')

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

Community
  • 1
  • 1
dydx
  • 157
  • 15
1

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