Reputation: 414
Im trying to use a WHERE IN
statement for the QueryBuilder.
I want to call
UPDATE tx_test SET hidden = 0 WHERE uid IN (1,2,3,4)
my code:
public function makeItemsVisible($itemsToShow)
{
$itemUids = implode(",", $itemsToShow);
$table = 'tx_test';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
$queryBuilder
->update($table)
->set('hidden', "0")
->where('uid IN (:uids)')
->setParameter('uids', $itemUids )
->execute();
}
The $itemUids 1,2,3,4
are correct, but the statement is only updating the first record in the Database. Do I missed something?
Upvotes: 1
Views: 1657
Reputation: 6460
You should use the expression builder and the API to add named parameters:
$queryBuilder
->update($table)
->set('hidden', 0)
->where($queryBuilder->expr()->in(
'uid',
$queryBuilder->createNamedParameter($itemUids, Connection::PARAM_INT_ARRAY)
)
->execute();
See the Comparisons section in the ExpressionBuilder
documentation for details.
Upvotes: 2