I've refactored out all privilege checking code into its own function and added test cases to handle (hopefully) any real world edge issue that may come up. See https://github.com/tractorcow/sapphire/blob/3.2-pdo-connector/tests/dev/MySQLDatabaseConfigurationHelperTest.php

As a part of this test I've also enforced some rules around validity of mysql-SS database names.

I still prefer checking permissions to actually creating and dropping a database just to see if the permission has been granted - It really seems like a rough and dirty way of doing such a check.

I do realise that my code is ugly, so I've tried to break down the logic into multiple functions to hopefully improve the readability.