How to add missing date month year in mysql (php)

Hi 

I have tried many solutions with MySQL but at the end, i found solution with PHP
which  is best 


$begin = new DateTime('2016-01-20');
$end = new DateTime('2017-12-10');

while ($begin <= $end) {
    echo $begin->format('Y-m'), "n";
    $begin->modify('first day of next month');
}