M
M
moem2019-06-04 11:09:52
PHP
moem, 2019-06-04 11:09:52

How to prepare query in PHP PDO with IN condition?

Hello.
Tell me, please, who knows.
On the backend, I connect to the sqlite database via PDO and form a query like:

select field1, field2, ...
from table1
where field1 in ('val1_1', 'val1_2', ... 'val1_N') 
and field2 in ('val2_1', 'val2_2', ... 'val2_N')

For which fields the request will be made and the number of searched values ​​is not known in advance.
How to use unnamed (?) pseudo-variables here, or do you just need to run each value through checking and escaping (like quote)?
What are good practices for preparing (prepare, execute) such queries?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question