for some reason my PDO prepared statement wasn't working on a particular part of a query but working else where in the same query. Whether I tried ? or :name to substitute the query information, it wasn't working. Maybe there is a bug...? Anyway, to get my query to work I have changed my query to
$sql = 'select ifnull('.$var.',0) from table';
instead of
$sql = 'select ifnull(?,0) from table';
or
$sql = 'select ifnull(:name,0) from table';
So I have concatenated the variable in the middle. My code is now working and I'm happy to continue with it this way because the variable is only defined by me, not user input defined so no worry of sql injection.
I am just wondering if anyone else is having to do this? Or if anyone can suggest why it wasn't working right before? Or even if there some obvious problem with this?