I'm working non-stop since too many hours (more than 14 -.-") and im falling asleep. Maybe this is the reason why I wasted more than 2 hours in trying to understand why my PDO query is not working. Here's the query:
$query = $mysql->prepare('SELECT * FROM table '.$where.'');
$query->execute($clauses);
Before it of course I define $where and $clauses:
$where["country"] = "country IN (:country)";
$clauses["country"] = "'".implode("','",array_keys($countries))."'"
Every row of the table has a 'country' column with country ISO code (e.g. FR, ES, IT, DE, US...). My $countries contains a key => value array like this one:
Array
(
ES => Spain
IT => Italy
DE => Germany
)
In conclusion as you clearly understand this is my $where:
country IN (:country)
Meanwhile my $clauses is:
'ES','IT','DE'
In other words the complete query string is:
country IN ('ES','IT','DE')
And don't worry, of course there's the WHERE statement in front of it. The query explained is this one:
SELECT * FROM table WHERE country IN ('ES','IT','DE')
It works on PHPMyAdmin but PDO always returns an empty array and I'm 99% sure that it's due to the fact that inside IN() there's nothing. I know this because if I change IN() into NOT IN() the query returns all rows of database. NOT IN(null) - yes, it's pseudo code I know it - means "everything" to my eyes. At this point I'm shocked.
Please if you think that the script strange or if you find it stupid or if you think that the problem is somewhere else don't focus on this. It's just an example. What you see here is not the real code and no, there's nothing wrong in other places. I've already debugged everything. Thank you for your time.