Array is masked as string in “IN” statement
문제
When using this DQL
$getImages = $em->createQuery('SELECT stuff
FROM MyBundle:MyModelClass
WHERE model.id NOT IN (:hide)')
->setParameter('hide', join(',', $hide), 'array');
The resulting SQL will be mapped to:
SELECT stuff FROM mymodelclass WHERE model.id NOT IN ('1,2,3');
Which is obviously wrong as it should be
SELECT stuff FROM mymodelclass WHERE model.id NOT IN (1,2,3);
So the query is fulfilled correclty. How can I tell doctrine to map the array without escaping it to a string?
해결책
Look at manual
$stmt = $conn->executeQuery('SELECT * FROM articles WHERE id IN (?)',
array(array(1, 2, 3, 4, 5, 6)),
array(\Doctrine\DBAL\Connection::PARAM_INT_ARRAY)
);
제휴하지 않습니다 StackOverflow