Fix PHP notices, trac #15058 & database cache bugs