I have the following PHP code which whows a weird behaviour. The system is backed by a PostgreSQL database, PHP version is 5.3.15.
$sql = "SELECT ce.id FROM calendar_events AS ce
WHERE ce.rowid = :rowid
AND ((SELECT count(*) FROM calendar_events_attendees AS cea WHERE cea.event_id = ce.id AND cea.status <> 'D') > 0
OR (SELECT count(*) FROM calendar_events_globalfnbl AS ceg WHERE ceg.event_id = ce.id AND ceg.status <> 'D') > 0)";
$stmt = db_prepare($sql); // Creates a PDOStatement
$stmt->bindValue(":rowid", $rowid, PDO::PARAM_INT);
$rv = $stmt->execute();
if($rv) {
return $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
}
else {
return null;
}
The query executes without errors but the function returns an empty array. There are definitely rows to find in the database, if I execute the query in pgAdmin (placeholder replaced by ID in question of course), it returns the rows I want to get.
I managed to find out that the sub-queries are the problem here. If I comment them out and use the following query, the rows are returned. But of course this does also return rows which I try to filter out with the sub-queries.
$sql = "SELECT ce.id FROM calendar_events AS ce
WHERE ce.rowid = :rowid";
Does PDO simply not support this type of sub-queries or is there any error in my code I cannot find?
Thanks in advance!