Well, the weakest point of PDO is inability to debug it because prepared statements are actually stored on a server side. I spent the whole day around the problem that I cannot understand at all. So, here is the case:
//the query itself
//Did other customers from the list buy the same style in last 3 months?
$end = date("Y-m-d H:i:s");
$start = strtotime("-3 month", strtotime($end));
$start = date('Y-m-d 00:00:00', $start);
$q = $db->prepare('SELECT COUNT(*) as totals FROM web_order
JOIN web_order_item ON web_order_item.od_id = web_order.od_id
WHERE web_order.p_vendor IN (:id)
AND od_pcode = :pcode
AND od_date BETWEEN :start AND :end
');
$q->bindValue(":pcode", '1008GD');
$q->bindValue(":id", $custList);
$q->bindValue(":start", $start);
$q->bindValue(":end", $end);
$q->execute();
echo "SELECT COUNT(*) as totals FROM web_order
JOIN web_order_item ON web_order_item.od_id = web_order.od_id
WHERE web_order.p_vendor IN ($custList)
AND od_pcode = '1008GD'
AND od_date BETWEEN '$start' AND '$end'";
$res = $q->fetchAll();
die(print_r($res));
And here comes the funny bit - print_r($res)
prints the empty array.
Array ( [0] => Array ( [totals] => 0 [0] => 0 ) )
While echo statement with exactly the same query prints
SELECT COUNT(*) as totals FROM web_order JOIN web_order_item ON web_order_item.od_id = web_order.od_id WHERE web_order.p_vendor IN ('210','1107','2295','2452') AND od_pcode = '1008GD' AND od_date BETWEEN '2012-06-13 00:00:00' AND '2012-09-13 13:15:36'
If I execute the echoed query by itself I get 'totals' column to have a value of 1. At the same moment PDO statement returns nothing.
Any help will be appreciated.
UPDATE: Although the answer was posted, I still do not get why this did not work. $custList is actually a string, not an array, because I used
$custList = implode(",", $custList);