Fix PHP warnings

see issue #134
move db check to first position, see

affects #122 and #91