Unit tests for db.php

Wrote some unit tests using PHPUnit. Will add more later, but this works already.