Honestly, the easiest and smartest way to do this is to add a table to your DB that has one record for every year and month.
Something like this:
and then have entries in it such as
And then you do
SELECT AM.monthYear, ...fields from other table[s]...
FROM allMonths AS AM LEFT JOIN yourTable AS T
ON ( Year(AM.monthYear) = Year(T.someDateField)
AND Month(AM.monthYear) = Month(T.someDateField)
I show this in a "Calendar of Events" where I create one record per *day* in order to show all dates in a given range. Here, on my demos page:
That's for ASP code, but the principle works the same for PHP, JSP, ASP.NET, etc.