Switch from MySQL to MySQLi

Also adds initial unit tests.