Make compatible with PHP 5.3

Also gets rid of the redundant db query.
Merge pull request #1 from hgtonight/patch-1

Make compatible with PHP 5.3