This is a backport of code from 'next'.

Reason for doing this now is to make it easier to improve our test cases with different config's.

Purpose of this from before was to reduce number of global variables, and to improve performance

I will generate a mantis bugtracker ID when i get back from going out today to track this pull request.

This pull request is ready for merging. Ideally, If people are happy, i'd like to get it in sooner rather than later as the test cases for DBAPI will build on this.

From memory, I think I may have had a +1 from someone when this was originally coded (as they liked the concept of reducing number of global variables)

Installation + Usage of mantis has been tested today (+previously)

SOAP API has only been tested today. I included PHPUNIT testing results as confirmation:

PHPUnit 3.7.28 by Sebastian Bergmann.

.....................................................S.SS......  63 / 136 ( 46%)
........S......SSSS.................S.......SS................. 126 / 136 ( 92%)
..........

Time: 45.44 seconds, Memory: 25.50Mb

OK, but incomplete or skipped tests!
Tests: 136, Assertions: 476, Skipped: 11.