src/ORM/DB.php
public static function set_alternative_database_name($name = null)
    {
        // Ignore if disabled
        if (!Config::inst()->get(static::class, 'alternative_database_enabled')) {
            return;
        }
        // Skip if CLI
        if (Director::is_cli()) {
            return;
        }
        // Validate name
        if ($name && !self::valid_alternative_database_name($name)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid alternative database name: "%s"',
                $name
            ));
        }

        // Set against session
        if (!Injector::inst()->has(HTTPRequest::class)) {
            return;
        }
        /** @var HTTPRequest $request */
        $request = Injector::inst()->get(HTTPRequest::class);
        if ($name) {
            $request->getSession()->set(self::ALT_DB_KEY, $name);
        } else {
            $request->getSession()->clear(self::ALT_DB_KEY);
        }
    }
public static function set_alternative_database_name($name = null)
    {
        // Ignore if disabled
        if (!Config::inst()->get(static::class, 'alternative_database_enabled')) {
            return;
        }
        // Skip if CLI
        if (Director::is_cli()) {
            return;
        }
        // Validate name
        if ($name && !self::valid_alternative_database_name($name)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid alternative database name: "%s"',
                $name
            ));
        }

        // Set against session
        if (!Injector::inst()->has(HTTPRequest::class)) {
            return;
        }
        /** @var HTTPRequest $request */
        $request = Injector::inst()->get(HTTPRequest::class);
        if ($name) {
            $request->getSession()->set(self::ALT_DB_KEY, $name);
        } else {
            $request->getSession()->clear(self::ALT_DB_KEY);
        }
    }
public static function set_alternative_database_name ( $ name = null ) { // Ignore if disabled if ( ! Config :: inst ( ) -> get ( static :: class , 'alternative_database_enabled' ) ) { return ; } // Skip if CLI if ( Director :: is_cli ( ) ) { return ; } // Validate name if ( $ name && ! self :: valid_alternative_database_name ( $ name ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid alternative database name: "%s"' , $ name ) ) ; } // Set against session if ( ! Injector :: inst ( ) -> has ( HTTPRequest :: class ) ) { return ; } /** @var HTTPRequest $request */ $ request = Injector :: inst ( ) -> get ( HTTPRequest :: class ) ; if ( $ name ) { $ request -> getSession ( ) -> set ( self :: ALT_DB_KEY , $ name ) ; } else { $ request -> getSession ( ) -> clear ( self :: ALT_DB_KEY ) ; } }
Set an alternative database in a browser cookie,
with the cookie lifetime set to the browser session.
This is useful for integration testing on temporary databases.

There is a strict naming convention for temporary databases to avoid abuse:
<prefix> (default: 'ss_') + tmpdb + <7 digits>
As an additional security measure, temporary databases will
be ignored in "live" mode.

Note that the database will be set on the next request.
Set it to null to revert to the main database.

@param string $name
Set an alternative database in a browser cookie with the cookie lifetime set to the browser session . This is useful for integration testing on temporary databases .