I got php fatal error after transfer server with php v5.6.19, before that I had no problem at all with following script
Fetch data from db table:
Update your while loop for that case when you get false from $shop->get_department_list() call
false
$shop->get_department_list()
updated while like this check for $depts if any data then get $dept:
$depts
$dept
while($depts && $dept = $depts->fetch_object()){