Fixed PHP notice when $result is not an object