C
C
coden552016-05-18 20:10:47
MySQL
coden55, 2016-05-18 20:10:47

How to pass in preparedstatement query to mysql an array of values ​​in IN()?

Query example: SELECT users FROM table WHERE id IN(?)
Googling found a discussion of the problem stackoverflow.com/questions/178479/preparedstateme...
from which it becomes clear that without crutches, you simply cannot substitute an array.
The answers are dated 2-3 years ago, maybe there is a solution at the moment?
Or it remains only to generate a preparedstatement with the necessary amount of IN(?,?,?....) for each request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2016-05-18
@Sanasol

Everything is done the same way.
And this is done in just a couple of lines.

$bind = ['somebind'];
$places = implode(', ', array_fill(0, count($bind), '?'));
$sqlpartial = " where column IN ($places) ";

V
vayho, 2016-05-19
@vayho

If you really want to write a short function that will fill in the PreparedStatement, then use some libraries to work with SQL. The first thing that comes to my mind is JdbcTemplate from spring-jdbc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question