N
N
Nikolay Alekseev2019-10-30 11:54:07
Laravel
Nikolay Alekseev, 2019-10-30 11:54:07

How to use IN in a raw Eloquent query?

Good day to all!
There is a system that uses raw user requests to the database and returns their result. The code is quite simple:

$results = DB::connection('mysql')->$queryType(DB::raw($q->QueryText), $params);

The $params variable contains an associative array with variables passed in by the user.
This works as long as IN is not used in the query.
Here a problem arises, if you give just an enumeration as a string (1, 2, 3), then, which is logical, the query returns zero rows, but if this enumeration is first converted into an array , then I get an error at the output: Array to string conversion
Obviously, he wants to see a string, not an array, but it's not clear how to solve this problem.
I would appreciate any advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2019-10-30
@FanatPHP

https://stackoverflow.com/a/14767651/285587

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question