Starts fancy stuff.

```php
$db->start_fancy_stuff();
// (void)
```
@return db
431694
public function start_fancy_stuff(): self
  {
    $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [db\query::class, [$this]]);
    $this->fancy = 1;
    return $this;
  }
451579
protected function start(){
        $name = 'create_'.str_plural(strtolower( $this->scaffoldCommandObj->argument('name') )).'_table';
        $path = $this->getPath($name);

        if ( ! $this->classExists($name))
        {
            $this->makeDirectory($path);
            $this->files->put($path, $this->compileMigrationStub());
            return $this->scaffoldCommandObj->info('+ ' . $path);
        }
        return $this->scaffoldCommandObj->comment('x ' . $path);
    }
148118
public function create()
    {
        $count = \count($this->options);

        if ($count === 1) {
            $config = \array_values($this->options)[0];
        } else {
            $index  = \random_int(0, $count - 1);
            $config = \array_values($this->options)[$index];
        }

        $db = new MySQL();
        $db->connect($config);

        return $db;
    }
877826
public function select()
    {
        $this->db->setQuery('USE ' . $this->db->quoteName($this->name))->execute();

        return $this;
    }
997421
public function begin() {
		if (!($this->connection instanceof \mysqli))
			throw new MySQLException("No valid MySQL connection available");
	
		if (version_compare(PHP_VERSION, '5.5.0') >= 0)
			return $this->connection->begin_transaction();
		
		return $this->connection->query("START TRANSACTION");
	}
397848
private function startQuery() {
    $connection = \Drupal::database();

    $query = $connection->select('users', 'u')->fields('u', ['uid']);
    $query->join('users_field_data', 'uf', 'uf.uid = u.uid');
    $query->leftJoin('profile', 'p', 'p.uid = u.uid');

    if ($this->useFullName()) {
      $query->leftJoin('profile__field_profile_first_name', 'fn', 'fn.entity_id = p.profile_id');
      $query->leftJoin('profile__field_profile_last_name', 'ln', 'ln.entity_id = p.profile_id');
    }

    if ($this->addNickName() === TRUE) {
      $query->leftJoin('profile__field_profile_nick_name', 'nn', 'nn.entity_id = p.profile_id');
    }

    $query->condition('uf.status', 1);

    return $query;
  }
710006
public static function load($db = null)
    {
        if (!isset(self::$_instance)) {
            self::$_instance = new Validator($db);
        }

        return self::$_instance;
    }
841149
private function conn()
    {
        if (!isset(self::$_db_handle[$this->db_config_name])) {
            $dbdriver = 'DB_' . Config::get('dbdriver');
            include_once __DIR__ . '/' . $dbdriver . '.php';

            $dbdriver = '\\ePHP\\Model\\' . $dbdriver;
            self::$_db_handle[$this->db_config_name] = $this->db = new $dbdriver($this->db_config_name);
        } else {
            $this->db = self::$_db_handle[$this->db_config_name];
        }

        return $this->db;
    }
78562
public function pdoWithoutDB()
    {
        $this->checkConfiguration();

        try {
            return new PDO(
                $this->buildDsn(false),
                $this->config['username'],
                $this->config['password']
            );
        } catch (Exception $e) {
            throw new RuntimeException(static::E_CONNECT);
        }
    }
358831
function db_init() {
        if ($this->is_configured() === false) {
            throw new moodle_exception('auth_dbcantconnect', 'auth_db');
        }

        // Connect to the external database (forcing new connection).
        $authdb = ADONewConnection($this->config->type);
        if (!empty($this->config->debugauthdb)) {
            $authdb->debug = true;
            ob_start(); //Start output buffer to allow later use of the page headers.
        }
        $authdb->Connect($this->config->host, $this->config->user, $this->config->pass, $this->config->name, true);
        $authdb->SetFetchMode(ADODB_FETCH_ASSOC);
        if (!empty($this->config->setupsql)) {
            $authdb->Execute($this->config->setupsql);
        }

        return $authdb;
    }
1085626
public function initializeDatabase()
    {
        // Get the database region
        $region = $this->input->getOption('db_region');
        $availableDbRegions = $this->getAvailableDbRegions();
        if (!in_array($region, $availableDbRegions)) {
            $q = new ChoiceQuestion(
                'Please select the region of your Cloud SQL instance '
                . sprintf('(defaults to %s)', self::DEFAULT_DB_REGION),
                $availableDbRegions,
                array_search(self::DEFAULT_DB_REGION, $availableDbRegions)
            );
            $q->setErrorMessage('DB region %s is invalid.');
            $region = $this->ask($q);
            $this->output->writeln("Using db_region <info>$region</info>");
        }

        // Get the other DB parameters
        $params = $this->askParameters([
            'project_id' => '',
            'db_instance' => '',
            'db_name' => '',
            'db_user' => 'root',
            'db_password' => '',
        ]);

        // Set the database connection string
        $params['db_connection'] = sprintf(
            '%s:%s:%s',
            $params['project_id'],
            $region,
            $params['db_instance']
        );

        // Set parameters for a local database
        $q = new ConfirmationQuestion(
            'Do you want to use the same db user and password for local run? '
            . '(Y/n)'
        );
        if ($this->ask($q)) {
            $params += [
                'local_db_user' => $params['db_user'],
                'local_db_password' => $params['db_password'],
            ];
        } else {
            $params += $this->askParameters([
                'local_db_user' => 'root',
                'local_db_password' => '',
            ]);
        }

        return $params;
    }
1331912
private function _getDefaultDB()
    {
        // For ReadDatabase checking Master first
        if ($this->_db) {
            return $this->_db;
        }
        
        if (!isset($this->db)) {
            get_instance()->load->database();
        }
        // No need to set as reference because $this->db is refered to &DB already.
        return get_instance()->db;
    }
774478
public function begin()
    {
        $context = $this->_context;

        $this->logger->info('transaction begin', 'db.transaction.begin');

        if ($context->transaction_level === 0) {
            $this->eventsManager->fireEvent('db:beginTransaction', $this);

            try {
                $connection = $this->poolManager->pop($this, $this->_timeout);

                if (!$connection->beginTransaction()) {
                    throw new DbException('beginTransaction failed.');
                }
                $context->connection = $connection;
            } catch (\PDOException $exception) {
                throw new DbException('beginTransaction failed: ' . $exception->getMessage(), $exception->getCode(), $exception);
            } finally {
                if (!$context->connection) {
                    $this->poolManager->push($this, $context);
                }
            }
        }

        $context->transaction_level++;
    }
1028418
public function run()
	{
        // Grab a list of tables
		$this->printTaskInfo('Getting list of tables.');
		$html = $this->loggedIn->getClient()->get('db_structure.php',
		[
			'query' =>
			[
				'db' => $this->remoteDbName,
				'server' => $this->loggedIn->getServerId(),
				'token' => $this->loggedIn->getToken()
			]
		])->getBody();

        // Extract a list of tables from the html
        $regex = '/<a href="sql\.php\?db=.*?table=(.*?)&amp;pos=0" title="">.*?<\/a>/i';
		if (preg_match_all($regex, $html, $matches) !== false)
        {
            if (isset($matches[1]))
            {
                $this->tables = $matches[1];
            }
        }

        // If we get to here assume everything worked.
        // The tables can be accessed by calling getTask()->getTables().
		return Result::success($this);
    }
1061634
protected function _buildSql()
    {
        if ($this->_db === null || is_string($this->_db)) {
            $this->_db = $this->getConnection();
        }

        if ($this->_union) {
            return $this->_getUnionSql();
        }

        if (!$this->_tables) {
            if ($this->_model) {
                $this->_tables[] = $this->getSource();
            } else {
                throw new MisuseException('at least one model is required to build the query');
            }
        }

        foreach ($this->_tables as $alias => $table) {
            if (is_string($table) && strpos($table, '\\') !== false) {
                /** @var \ManaPHP\Model $model */
                $model = $this->_di->getShared($table);
                $this->_tables[$alias] = $model->getSource($this->_bind);
            }
        }

        $params = [];
        if ($this->_distinct) {
            $params['distinct'] = true;
        }

        if ($this->_fields !== null) {
            $fields = $this->_fields;
        } elseif (count($this->_tables) === 1) {
            $fields = $this->_model ? '[' . implode('], [', $this->_model->getFields()) . ']' : '*';
        } else {
            $fields = '';
            $selectedFields = [];
            foreach ($this->_tables as $alias => $table) {
                $selectedFields[] = '[' . (is_string($alias) ? $alias : $table) . '].*';
            }
            $fields .= implode(', ', $selectedFields);
        }
        $params['fields'] = $fields;

        $selectedTables = [];

        foreach ($this->_tables as $alias => $table) {
            if ($table instanceof $this) {
                if (is_int($alias)) {
                    throw new NotSupportedException('if using SubQuery, you must assign an alias for it');
                }

                $selectedTables[] = '(' . $table->getSql() . ') AS [' . $alias . ']';
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $this->_bind = array_merge($this->_bind, $table->getBind());
            } elseif (is_string($alias)) {
                $selectedTables[] = '[' . $table . '] AS [' . $alias . ']';
            } else {
                $selectedTables[] = '[' . $table . ']';
            }
        }

        $params['from'] = implode(', ', $selectedTables);

        $joinSQL = '';
        /** @noinspection ForeachSourceInspection */
        foreach ($this->_joins as $join) {
            list($joinTable, $joinCondition, $joinAlias, $joinType) = $join;

            if ($joinAlias !== null) {
                $this->_tables[$joinAlias] = $joinTable;
            } else {
                $this->_tables[] = $joinTable;
            }

            if ($joinType !== null) {
                $joinSQL .= ' ' . $joinType;
            }

            if ($joinTable instanceof $this) {
                $joinSQL .= ' JOIN (' . $joinTable->getSql() . ')';
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $this->_bind = array_merge($this->_bind, $joinTable->getBind());
                if ($joinAlias === null) {
                    throw new NotSupportedException('if using SubQuery, you must assign an alias for it');
                }
            } else {
                $joinSQL .= ' JOIN [' . $joinTable . ']';
            }

            if ($joinAlias !== null) {
                $joinSQL .= ' AS [' . $joinAlias . ']';
            }

            if ($joinCondition) {
                $joinSQL .= ' ON ' . $joinCondition;
            }
        }
        $params['join'] = $joinSQL;

        $wheres = [];
        foreach ($this->_conditions as $v) {
            $wheres[] = stripos($v, ' or ') ? "($v)" : $v;
        }

        if ($wheres) {
            $params['where'] = implode(' AND ', $wheres);
        }

        if ($this->_group !== null) {
            $params['group'] = $this->_group;
        }

        if ($this->_having !== null) {
            $params['having'] = $this->_having;
        }

        if ($this->_order !== null) {
            $params['order'] = $this->_order;
        }

        if ($this->_limit !== null) {
            $params['limit'] = $this->_limit;
        }

        if ($this->_offset !== null) {
            $params['offset'] = $this->_offset;
        }

        if ($this->_forUpdate) {
            $params['forUpdate'] = $this->_forUpdate;
        }

        $sql = $this->_db->buildSql($params);
        //compatible with other SQL syntax
        $replaces = [];
        foreach ($this->_bind as $key => $_) {
            $replaces[':' . $key . ':'] = ':' . $key;
        }

        $sql = strtr($sql, $replaces);

        foreach ($this->_tables as $table) {
            if (!$table instanceof $this) {
                $source = $table;
                if (strpos($source, '.')) {
                    $source = '[' . implode('].[', explode('.', $source)) . ']';
                } else {
                    $source = '[' . $source . ']';
                }
                $sql = str_replace('[' . $table . ']', $source, $sql);
            }
        }

        return $sql;
    }
277793
public function getMainDB()
    {
        if ($this->main_database === null &&
            ($this->isOperationModeCLI() || $this->isOperationModeStandalone())
        ) {
            $this->registerMainDatabase();
        }
        return $this->main_database;
    }
916392
protected function db(): Database
    {
        $conn = app(Pool::class)->getConnection();
        $database = $conn->defaultDatabase;

        return $conn->getRawConnection()->$database;
    }