I have a query that looks like this :
$cleanupQuery = $conn->prepare("
DELETE FROM tbl_annotations
WHERE
id IN (:removedAnnotations)
");
Obviously, the point is to end up with this kind of query
DELETE FROM tbl_annotations WHERE id IN (1, 2, 3, 4)
Is this possible with Zend Framework 2?
If not, is there a solution for this problem?
Update
Despite some people's decision to make this question as a duplicate, I have chosen an alternate solution : FIND_IN_SET().
$cleanupQuery = $conn->prepare("
DELETE FROM tbl_annotations
WHERE
FIND_IN_SET(id, :removedAnnotations)
");
And I have removedAnnotations
set via implode(',', $annotationIds)
. These ids are already filtered through a validation function, so I know they are all integers.
This works in my case, but it would certainly break when using direct input from the user.
Do not use this method unless all array values are guaranteed to be sanitized.