I'd like to make a pdo pgsql query with an IN operator where the value - witch come from a variable - also contains single id-s, and array from id-s like that:
UPDATE:
if ($_POST['select'] == '1') {
$id= 109;
} elseif ($_POST['select'] == '2') {
$id= 111;
} elseif ($_POST['select'] == '3') {
$id= 117;
} elseif ($_POST['select'] == '4') {
$id= 114;
} elseif ($_POST['select'] == '5') {
$id= [108, 107, 101, 103];
} else {
$id=NULL;
}
The query looks like that:
$result = "SELECT * FROM table
WHERE table.id IN (:id)";
$query = $pgConn->prepare($result);
$query->bindparam(':id', $id);
$query->execute();
I’d try to convert the array to sting in multiple ways, but the query returns always the same error: “invalid input syntax for integer”
One attempt like:
$ids_string = "'".implode("','", $id)."'";
returns: invalid input syntax for integer: "'108','107','101','103'"'
The other - subsidiary - problem is to using single and array id-s from the same variable but I think is manageable later with an if-else statement.
Thanks for the help!