Prepared query using IN condition with sql in a doctrine repository


Nov 6, 2021 Symfony




$inputIds = [1,2,3];

$conn = $this->_em->getConnection();
$in  = str_repeat('?,', count($inputIds) - 1) . '?';//generate parameters
$sql = "select * from my_table where id IN ($in)";
$stmt = $conn->prepare($sql);
$res = $stmt->executeQuery($inputIds);
return $res->fetchAllAssociative();

 


symfony
security
sql
short