Run queries in testConnect

Added $query parameter to testConnect for installer to run SQL queries
before database name is known
Removed "no database" condition from mian connect() function
Use testConnect query

Where required, run queries on server with no database named
Removed superfluous reconnections
Remove extra connect(), fix typo, fix TV template assignment

Use existing connection from testConnect
Correct typo in error message call
Allow for TV .tpl having assignment to non-existent template (but leaves
suspect tests on the resources returned from queries)