Initialize database

@return array (status, result)
772514
function init($dryrun = true) {

		$has_history_table = $this->has_history_table();

		if ($this->locked && $has_history_table && ! $dryrun) {
			// operation is destructive and database is locked
			return [null, 401];
		}
		else { // database is not locked

			$channels = $this->channels();

			$status = [
				// ordered list of versions in processing order
				'history' => [],
				// current version for each channel
				'state' => [],
				// active channels
				'active' => [],
				// checklist of version requirements
				'checklist' => $this->generate_checklist($channels)
			];

			if ( ! $dryrun) {
				if ($has_history_table) {
					$this->rm();
				}
				else { // no history table available
					$this->log("Skipped uninstall. Database is clean.\n");
				}
			}

			// generate version history for full reset
			foreach ($channels as $channel => & $timeline) {
				if (count($timeline['versions']) > 0) {
					end($timeline['versions']);
					$last_version = key($timeline['versions']);
					$this->processhistory($channel, $last_version, $status, $channels);
				}
			}

			// dry run?
			if ($dryrun) {

				if ($has_history_table) {
					list($rm_tables, $err) = $this->rm($dryrun);
				}
				else { // no history table available
					$rm_tables = [];
				}

				// just return the step history
				return [ [ 'history' => $status['history'], 'rm' => $rm_tables ], 0];
			}

			// execute the history
			foreach ($status['history'] as $entry) {
				// execute migration
				$this->processmigration($channels, $entry['channel'], $entry['version'], $entry['hotfix']);
			}

			// operation complete
			return [null, 0];
		}
	}
160461
public function init()
    {
        phpCAS::traceBegin();
        // if the storage has already been initialized, return immediatly
        if ($this->isInitialized()) {
            return;
        }

        // initialize the base object
        parent::init();

        // create the PDO object if it doesn't exist already
        if (!($this->_pdo instanceof PDO)) {
            try {
                $this->_pdo = new PDO(
                    $this->_dsn, $this->_username, $this->_password,
                    $this->_driver_options
                );
            }
            catch(PDOException $e) {
                phpCAS::error('Database connection error: ' . $e->getMessage());
            }
        }

        phpCAS::traceEnd();
    }
1175646
public function init()
    {

        // initialize the parend class
        parent::init();

        // initialize the prepared statements
        $this->categoryVarcharsStmt =
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CATEGORY_VARCHARS));
        $this->categoryVarcharsByPkAndStoreIdStmt =
            $this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CATEGORY_VARCHARS_BY_PK_AND_STORE_ID));
    }
1122260
protected function initialize()
    {
        if (!is_array($this->queryResult)) {
            $this->queryResult = $this->dataMapper->mapToObjects($this->persistenceManager->getObjectDataByQuery($this->query));
        }
    }
127501
protected function init() {
		
		if (!($this->options['host'] || $this->options['socket'])
		||  !$this->options['user'] 
		||  !$this->options['pass'] 
		||  !$this->options['db']
		||  !$this->options['path']
		||  !$this->options['files_table']) {
			return false;
		}
		
		
		$this->db = new mysqli($this->options['host'], $this->options['user'], $this->options['pass'], $this->options['db'], $this->options['port'], $this->options['socket']);
		if ($this->db->connect_error || @mysqli_connect_error()) {
			return false;
		}
		
		$this->db->set_charset('utf8');

		if ($res = $this->db->query('SHOW TABLES')) {
			while ($row = $res->fetch_array()) {
				if ($row[0] == $this->options['files_table']) {
					$this->tbf = $this->options['files_table'];
					break;
				}
			}
		}

		if (!$this->tbf) {
			return false;
		}

		$this->updateCache($this->options['path'], $this->_stat($this->options['path']));

		return true;
	}
916452
public function getDatabases(): array
    {
        $result = [];
        foreach (array_keys($this->config['databases'] ?? []) as $database) {
            $result[$database] = $this->getDatabase($database);
        }

        return $result;
    }
1316469
function init()
    {
        $this->_a['verbose'] = 'tenant_spas';
        $this->_a['table'] = 'tenant_spas';
        $this->_a['cols'] = array(
            'id' => array(
                'type' => 'Pluf_DB_Field_Sequence',
                'blank' => true
            ),
            'state' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => false,
                'size' => 50,
                'readable' => true,
                'editable' => false
            ),
            'name' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => false,
                'size' => 50,
                'readable' => true,
                'editable' => false
            ),
            'version' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => false,
                'size' => 100,
                'readable' => true,
                'editable' => false
            ),
            'last_version' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_nulls' => false,
                'size' => 100,
                'readable' => true,
                'editable' => false
            ),
            'title' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => true,
                'size' => 50,
                'readable' => true,
                'editable' => true
            ),
            'license' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => true,
                'size' => 250,
                'readable' => true,
                'editable' => false
            ),
            'description' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => true,
                'size' => 250,
                'editable' => false
            ),
            'path' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => false,
                'size' => 100,
                'verbose' => 'SPA installation path',
                'readable' => false,
                'editable' => false
            ),
            'main_page' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => false,
                'default' => 'index.html',
                'size' => 100,
                'readable' => false,
                'editable' => false
            ),
            'homepage' => array(
                'type' => 'Pluf_DB_Field_Varchar',
                'is_null' => true,
                'size' => 100
            ),
            'creation_dtime' => array(
                'type' => 'Pluf_DB_Field_Datetime',
                'is_null' => true,
                'readable' => true,
                'editable' => false
            ),
            'modif_dtime' => array(
                'type' => 'Pluf_DB_Field_Datetime',
                'is_null' => true,
                'readable' => true,
                'editable' => false
            )
        );

        $this->_a['idx'] = array(
            'spa_idx' => array(
                'col' => 'name, version',
                'type' => 'unique', // normal, unique, fulltext, spatial
                'index_type' => '', // hash, btree
                'index_option' => '',
                'algorithm_option' => '',
                'lock_option' => ''
            )
        );

        $this->_a['views'] = array();
    }
1128551
public static function initializeDatabaseConnections()
    {
        // for backward compatibility, don't use MAX_DB_CONNECTION_INDEX directly,
        // but check if MAX_DB_CONNECTION_INDEX is defined
        $intMaxIndex = defined('MAX_DB_CONNECTION_INDEX') ? constant('MAX_DB_CONNECTION_INDEX') : 9;

        if (defined('DB_CONNECTION_0')) {
            // This causes a conflict with how DbBackedSessionHandler works.
            throw new \Exception('Do not define DB_CONNECTION_0. Start at DB_CONNECTION_1');
        }

        for ($intIndex = 1; $intIndex <= $intMaxIndex; $intIndex++) {
            $strConstantName = sprintf('DB_CONNECTION_%s', $intIndex);

            if (defined($strConstantName)) {
                // Expected Keys to be Set
                $strExpectedKeys = array(
                    'adapter',
                    'server',
                    'port',
                    'database',
                    'username',
                    'password',
                    'profiling',
                    'dateformat'
                );

                // Lookup the Serialized Array from the DB_CONFIG constants and unserialize it
                $strSerialArray = constant($strConstantName);
                $objConfigArray = unserialize($strSerialArray);

                // Set All Expected Keys
                foreach ($strExpectedKeys as $strExpectedKey) {
                    if (!array_key_exists($strExpectedKey, $objConfigArray)) {
                        $objConfigArray[$strExpectedKey] = null;
                    }
                }

                if (!$objConfigArray['adapter']) {
                    throw new \Exception('No Adapter Defined for ' . $strConstantName . ': ' . var_export($objConfigArray,
                            true));
                }

                if (!$objConfigArray['server']) {
                    throw new \Exception('No Server Defined for ' . $strConstantName . ': ' . constant($strConstantName));
                }

                $strDatabaseType = 'QCubed\\Database\\' . $objConfigArray['adapter'] . '\\Database';

                //if (!class_exists($strDatabaseType)) {
                //	throw new \Exception('Database adapter was not found: ' . $objConfigArray['adapter']);
                //}

                self::$Database[$intIndex] = new $strDatabaseType($intIndex, $objConfigArray);
            }
        }
    }
643292
protected static function initDB() {
        $dbConfig = static::getConfig('db', static::getServer());
        static::$db = new Connection($dbConfig['dsn'], $dbConfig['user'], $dbConfig['password'], $dbConfig['options']);
        static::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        if (!empty($dbConfig['tablePrefix']))
            static::$db->setTablePrefix($dbConfig['tablePrefix']);
    }
718577
public function init()
{
    $job = $this->job = new \PHPDaemon\Core\ComplexJob(function ($job) { // called when job is done

        $job->keep();
        $this->wakeup(); // wake up the request immediately

    });

    $job('select', function ($name, $job) { // registering job named 'select'

        $this->appInstance->sql->getConnection(function ($sql) use ($name, $job) {
            if (!$sql->isConnected()) {
                $job->setResult($name, null);
                return null;
            }
            $sql->query('SELECT 123, "string"', function ($sql, $success) use ($job, $name) {

                $job('showdbs', function ($name, $job) use ($sql) { // registering job named 'showdbs'
                    $sql->query('SHOW DATABASES', function ($sql, $t) use ($job, $name) {
                        $job->setResult($name, $sql->resultRows);
                    });
                });
                $job->setResult($name, $sql->resultRows);
            });
            return null;
        });
    });

    $job(); // let the fun begin

    $this->sleep(5, true); // setting timeout
}
625290
function databaseInitialize() {
  // on the first load of (non-existent database), we will have no collections so we can 
  //   detect the absence of our collections and add (and configure) them now.
  var entries = db.getCollection("entries");
  if (entries === null) {
    entries = db.addCollection("entries");
  }

  // kick off any program logic or start listening to external events
  runProgramLogic();
}
907547
public function initialize()
    {
        $initializationQuery = 'INSERT INTO tx_solr_indexqueue_item (root, item_type, item_uid, indexing_configuration, indexing_priority, changed, errors) '
            . $this->buildSelectStatement() . ',"" '
            . 'FROM ' . $this->type . ' '
            . 'WHERE '
            . $this->buildPagesClause()
            . $this->buildTcaWhereClause()
            . $this->buildUserWhereClause();
        $logData = ['query' => $initializationQuery];

        try {
            $logData['rows'] = $this->queueItemRepository->initializeByNativeSQLStatement($initializationQuery);
        } catch (DBALException $DBALException) {
            $logData['error'] = $DBALException->getCode() . ': ' . $DBALException->getMessage();
        }

        $this->logInitialization($logData);
        return true;
    }
555244
static function init()
    {
        if (SettingsDatabase::NEED_CONNECT) {
            $connection_string = 'mysql:host=' . SettingsDatabase::HOST . ';port=' . SettingsDatabase::PORT . ';dbname=' . SettingsDatabase::DBNAME;

            ORM::configure('connection_string', $connection_string);
            ORM::configure('username', SettingsDatabase::USERNAME);
            ORM::configure('password', SettingsDatabase::PASSWORD);
            ORM::configure('logging', SettingsDatabase::LOGGING);
            ORM::configure('driver_options', [
                PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
            ]);
        }
    }
392405
public function initialize()
    {
        $messages = [
            new DownloadSettings()
        ];

        $collection = $this->service->batchExecute(
            $messages,
            $this->position
        );

        $responses = [];
        foreach ($collection as $response) {
            $responses[] = $response;
        }

        return array_map(function($response, Request $message){
            return $message->getResponse($response);
        }, $responses, $messages);
    }
449243
protected function init()
    {
        if (empty($this->data['databaseRow']['config'])) {
            $rows = [[['colspan' => 1, 'rowspan' => 1, 'spanned' => 0, 'name' => '0x0']]];
            $colCount = 1;
            $rowCount = 1;
        } else {
            /** @var LayoutSetup $layoutSetup */
            $layoutSetup = GeneralUtility::makeInstance(LayoutSetup::class)->init(0);
            if ($this->data['tableName'] === 'tx-gridelements_backend_layout') {
                $layoutId = $this->data['databaseRow']['alias'] ?: (int)$this->data['databaseRow']['uid'];
                $layout = $layoutSetup->getLayoutSetup($layoutId);
            } else {
                $parser = GeneralUtility::makeInstance(TypoScriptParser::class);
                $parser->parse($this->data['databaseRow']['config']);
                $layout = ['config' => $parser->setup['backend_layout.']];
                if (!empty($layout['config']['rows.'])) {
                    $columns = $layoutSetup->checkAvailableColumns($layout);
                    if ($columns['allowed'] || $columns['disallowed'] || $columns['maxitems']) {
                        $layout['columns'] = $columns;
                        unset($layout['columns']['allowed']);
                        $layout['allowed'] = $columns['allowed'] ?: [];
                        $layout['disallowed'] = $columns['disallowed'] ?: [];
                        $layout['maxitems'] = $columns['maxitems'] ?: [];
                    }
                }
            }
            $rows = [];
            $colCount = $layout['config']['colCount'];
            $rowCount = $layout['config']['rowCount'];
            $dataRows = $layout['config']['rows.'];
            $spannedMatrix = [];
            for ($i = 1; $i <= $rowCount; $i++) {
                $cells = [];
                $row = array_shift($dataRows);
                $columns = $row['columns.'];
                for ($j = 1; $j <= $colCount; $j++) {
                    $cellData = [];
                    if (!$spannedMatrix[$i][$j]) {
                        if (is_array($columns) && !empty($columns)) {
                            $column = array_shift($columns);
                            if (isset($column['colspan'])) {
                                $cellData['colspan'] = (int)$column['colspan'];
                                $columnColSpan = (int)$column['colspan'];
                                if (isset($column['rowspan'])) {
                                    $columnRowSpan = (int)$column['rowspan'];
                                    for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
                                        for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
                                            $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
                                        }
                                    }
                                } else {
                                    for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
                                        $spannedMatrix[$i][$j + $spanColumn] = 1;
                                    }
                                }
                            } else {
                                $cellData['colspan'] = 1;
                                if (isset($column['rowspan'])) {
                                    $columnRowSpan = (int)$column['rowspan'];
                                    for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
                                        $spannedMatrix[$i + $spanRow][$j] = 1;
                                    }
                                }
                            }
                            if (isset($column['rowspan'])) {
                                $cellData['rowspan'] = (int)$column['rowspan'];
                            } else {
                                $cellData['rowspan'] = 1;
                            }
                            if (isset($column['name'])) {
                                $cellData['name'] = $column['name'];
                            }
                            if (isset($column['colPos'])) {
                                $colPos = (int)$column['colPos'];
                                $cellData['column'] = $colPos;
                                $cellData['allowed'] = [];
                                if (isset($layout['allowed'][$colPos])) {
                                    foreach ($layout['allowed'][$colPos] as $key => $valueArray) {
                                        $cellData['allowed'][$key] = implode(',', array_keys($valueArray));
                                    }
                                }
                                $cellData['disallowed'] = [];
                                if (isset($layout['disallowed'][$colPos])) {
                                    foreach ($layout['disallowed'][$colPos] as $key => $valueArray) {
                                        $cellData['disallowed'][$key] = implode(',', array_keys($valueArray));
                                    }
                                }
                                $cellData['maxitems'] = (int)$layout['maxitems'][$colPos];
                            }
                        }
                    } else {
                        $cellData = ['colspan' => 1, 'rowspan' => 1, 'spanned' => 1];
                    }
                    $cells[] = $cellData;
                }
                $rows[] = $cells;
                if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) {
                    ksort($spannedMatrix[$i]);
                }
            }
        }
        $this->rows = $rows;
        $this->colCount = (int)$colCount;
        $this->rowCount = (int)$rowCount;
    }
225471
public function loadResult()
	{
		$this->connect();

		$ret = null;

		// Execute the query and get the result set cursor.
		if (!($cursor = $this->execute()))
		{
			return null;
		}

		// Get the first row from the result set as an array.
		$row = $this->fetchArray($cursor);

		if ($row)
		{
			$ret = $row[0];
		}

		// Free up system resources and return.
		$this->freeResult($cursor);

		return $ret;
	}
201147
public function dbInit()
    {
      $mongo_index = ( (phpversion('mongo') >= '1.5.0') ? ('createIndex') : ('ensureIndex') );
      $this->log("maint: {$mongo_index} on ".$this->getConfig('collection'));
      $this->sessions->$mongo_index(array(
                                          'last_accessed' => 1
                                          ));
      $this->log("maint: {$mongo_index} on ".$this->getConfig('lockcollection'));
      $this->locks->$mongo_index(array(
                                       'created' => 1
                                       ));
    }