Save data

@param  array $database
array (
'driver' => 'pdo_mysql',
'host' => 'localhost',
'dbname' => 'espocrm_test',
'user' => 'root',
'password' => '',
),
@param  string $language
@return bool
193300
public function saveData($database, $language)
    {
        $initData = include('install/core/afterInstall/config.php');
        $siteUrl = $this->getSystemHelper()->getBaseUrl();
        $databaseDefaults = $this->app->getContainer()->get('config')->get('database');

        $data = array(
            'database' => array_merge($databaseDefaults, $database),
            'language' => $language,
            'siteUrl' => $siteUrl,
            'passwordSalt' => $this->getPasswordHash()->generateSalt(),
            'cryptKey' => $this->getContainer()->get('crypt')->generateKey()
        );

        $owner = $this->getFileManager()->getPermissionUtils()->getDefaultOwner(true);
        $group = $this->getFileManager()->getPermissionUtils()->getDefaultGroup(true);

        if (!empty($owner)) {
            $data['defaultPermissions']['user'] = $owner;
        }
        if (!empty($group)) {
            $data['defaultPermissions']['group'] = $group;
        }

        $data = array_merge($data, $initData);
        $result = $this->saveConfig($data);

        return $result;
    }
1212896
public function reload( string $language ): bool
	{
		$language = trim( $language );
		if( ! self::valid($language) )
		{
			return false;
		}

		if( $this->language === $language && $this->lang_init )
		{
			return true;
		}

		$packages = is_null($this->lang) ? [] : $this->lang->packages();
		$this->language = $language;
		$this->lang = null;
		$this->lang_init = true;
		$this->proxy = [];

		$event = new LanguageLoadEvent($this);
		EventManager::dispatch(
			$event,
			function( $result ) use($event) {
				if( $result instanceof Language )
				{
					$this->lang = $result;
					$event->stopPropagation();
				}
			});

		if( is_null($this->lang) )
		{
			$this->lang = new LanguageFiles($language);
		}

		$this->lang_i18 = $this->lang instanceof I18Interface;
		$this->lang_transliteration = $this->lang instanceof TransliterationInterface;
		$this->lang_text = $this->lang instanceof TextInterface;
		$this->lang_is_default = $this->lang === $this->lang_default;

		foreach($packages as $package)
		{
			$this->lang->load($package);
		}

		return true;
	}
605479
public function saveinnlang()
    {
        parent::save();

        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        if (isset($aParams['oxcontents__oxloadid'])) {
            $aParams['oxcontents__oxloadid'] = $this->_prepareIdent($aParams['oxcontents__oxloadid']);
        }

        // checkbox handling
        if (!isset($aParams['oxcontents__oxactive'])) {
            $aParams['oxcontents__oxactive'] = 0;
        }

        $oContent = oxNew(\OxidEsales\Eshop\Application\Model\Content::class);

        if ($soxId != "-1") {
            $oContent->loadInLang($this->_iEditLang, $soxId);
        } else {
            $aParams['oxcontents__oxid'] = null;
        }

        $oContent->setLanguage(0);
        $oContent->assign($aParams);

        // apply new language
        $oContent->setLanguage(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("new_lang"));
        $oContent->save();

        // set oxid if inserted
        $this->setEditObjectId($oContent->getId());
    }
37872
public function saveToDb($text, $phone, $message)
    {
        if (!$this->saveToDb) {
            return false;
        }
        $model = new TurboSmsSent();
        $model->text = $text;
        $model->phone = $phone;
        $model->message = $message . ($this->debug ? $this->debugSuffixMessage : '');
        if ($this->lastSendMessageId) {
            $model->message_id = $this->lastSendMessageId;
        }
        $model->status = $this->sendStatus;
        $model->save();

        if ((int)$model->id) {
            $this->lastSendMessagesIds[$model->id] = $this->lastSendMessageId;
        }

        return true;
    }
27232
public function insertLanguage(Language $language)
    {
        $query = $this->dbHandler->createSelectQuery();
        $query->select(
            $query->expr->max($this->dbHandler->quoteColumn('id'))
        )->from($this->dbHandler->quoteTable('ezcontent_language'));

        $statement = $query->prepare();
        $statement->execute();

        $lastId = (int)$statement->fetchColumn();

        // Legacy only supports 8 * PHP_INT_SIZE - 2 languages:
        // One bit cannot be used because PHP uses signed integers and a second one is reserved for the
        // "always available flag".
        if ($lastId == (2 ** (8 * PHP_INT_SIZE - 2))) {
            throw new RuntimeException('Maximum number of languages reached!');
        }
        // Next power of 2 for bit masks
        $nextId = ($lastId !== 0 ? $lastId << 1 : 2);

        $query = $this->dbHandler->createInsertQuery();
        $query->insertInto(
            $this->dbHandler->quoteTable('ezcontent_language')
        )->set(
            $this->dbHandler->quoteColumn('id'),
            $query->bindValue($nextId, null, \PDO::PARAM_INT)
        );
        $this->setCommonLanguageColumns($query, $language);

        $query->prepare()->execute();

        return $nextId;
    }
944275
private function saveLanguageIntoCookie($language)
    {
        $cookie = new Cookie([
            'name' => $this->cookieName,
            'value' => $language,
            'expire' => time() + 86400 * $this->expireDays,
        ]);
        Yii::$app->response->cookies->add($cookie);
    }
1204607
public static function set($language = null)
    {
        self::$messages = array();
        $language = $language ?: self::$config['language'];
        $filename = Atomik::findFile("$language.php", Atomik::path(self::$config['dir']));
        if ($filename === false) {
            throw new AtomikException("Language '$language' does not exists");
        }
        
        $messages = include $filename;
        if (is_array($messages)) {
            self::$messages = array_merge(self::$messages, $messages);
        }
        
        Atomik::set('app.language', $language);
        self::$config['language'] = $language;
        if (isset($_SESSION)) {
            $_SESSION['__LANG'] = $language;
        }
    }
1274419
private function createXMLDoc(Database $database)
    {
        $doc = new DOMDocument('1.0', 'utf-8');
        $doc->formatOutput = true; // pretty printing
        $doc->appendChild($doc->createComment("Created by PropelDataDumpTask."));

        $dsNode = $doc->createElement("dataset");
        $dsNode->setAttribute("name", "all");
        $doc->appendChild($dsNode);

        $platform = $this->getGeneratorConfig()->getConfiguredPlatform($this->conn);

        $this->log("Building DOM tree containing data from tables:");

        foreach ($database->getTables() as $tbl) {
            $this->log("\t+ " . $tbl->getName());
            $stmt = $this->getTableDataStmt($tbl->getName(), $platform);
            while ($row = $stmt->fetch()) {
                $rowNode = $doc->createElement($tbl->getPhpName());
                foreach ($tbl->getColumns() as $col) {
                    $cval = $row[$col->getName()];
                    if ($cval !== null) {
                        $rowNode->setAttribute($col->getPhpName(), iconv($this->dbEncoding, 'utf-8', $cval));
                    }
                }
                $dsNode->appendChild($rowNode);
                unset($rowNode);
            }
            unset($stmt);
        }

        return $doc;
    }
225388
public static function createDatabase()
  {
      $ddl = file_get_contents('verbs.sql');
      if (file_exists('verbs.db')) {
          unlink('verbs.db');
      }
      $connection = new PDO('sqlite:verbs.db');
      $connection->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
      $connection->exec($ddl);

      $entries = simplexml_load_file('JMdict');
      if ($entries === false) {
        echo 'Could not open JMdict file' . PHP_EOL;
      }

      $connection->beginTransaction();
      $sql = 'INSERT INTO verbs (kanji, kana, type) VALUES (:kanji, :kana, :type)';
      $statement = $connection->prepare($sql);

      foreach ($entries as $entry) {
        $poses = [];
        foreach ($entry->xpath('sense/pos') as $pos) {
          $poses[] = array_keys(get_object_vars($pos))[0];
        }

        foreach ($poses as $pos) {
          if (stripos($pos, 'v1') !== false || stripos($pos, 'v5') !== false || $pos == 'vz' || $pos == 'vk' || $pos == 'vn' || $pos == 'vr' || $pos == 'vs-s' || $pos == 'vs-i') {
            $kanji = $entry->k_ele->keb;
            $kana = $entry->r_ele->reb;
            $saved = $statement->execute(array(':kanji' => $kanji, ':kana' => $kana, ':type' => $pos));
            if ($saved === false) {
              die('Could not save entry : ' . implode(' ', $statement->errorInfo()));
            }
          }
        }
      }
      $connection->commit();
  }
369681
public static function setLanguage($language)
    {
        if (in_array($language, self::$languages)) {
            self::$language = $language;
            self::$strings = self::loadLanguage();
            return true;
        }

        return false;
    }
361594
public function updateLanguage(Language $language)
    {
        try {
            return $this->innerGateway->updateLanguage($language);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
46657
public function connect($host = false, $user = false, $password = false, $database = false, $newLink = false)
    {
        $this->connection = mysqli_connect($host, $user, $password, $newLink);

        if ($this->connection) {
            if ($this->selectDatabase($database)) {
                $this->query("SET CHARACTER SET utf8");
                $this->query("SET NAMES utf8");
                return $this->connection;
            } else {
                $message = 'Cannot select database ' . $database;
            }
        } else {
            $message = mysqli_error($this->connection);
        }

        if (!$this->connection) {
            trigger_error($message, E_USER_WARNING);
        }
    }
707254
public static function create(Database $database)
    {
        $dotSyntax = '';

        // table nodes
        foreach ($database->getTables() as $table) {
            $columnsSyntax = '';
            foreach ($table->getColumns() as $column) {
                $attributes = '';

                if (count($column->getForeignKeys()) > 0) {
                    $attributes .= ' [FK]';
                }

                if ($column->isPrimaryKey()) {
                    $attributes .= ' [PK]';
                }

                $columnsSyntax .= sprintf('%s (%s)%s\l', $column->getName(), $column->getType(), $attributes);
            }

            $nodeSyntax = sprintf('"%s" [label="{<table>%s|<cols>%s}", shape=record];', $table->getName(), $table->getName(), $columnsSyntax);
            $dotSyntax .= "$nodeSyntax\n";
        }

        // relation nodes
        foreach ($database->getTables() as $table) {
            foreach ($table->getColumns() as $column) {
                foreach ($column->getForeignKeys() as $fk) {
                    $relationSyntax = sprintf('"%s":cols -> "%s":table [label="%s=%s"];', $table->getName(), $fk->getForeignTableName(), $column->getName(), implode(',', $fk->getForeignColumns()));
                    $dotSyntax .= "$relationSyntax\n";
                }
            }
        }

        return sprintf("digraph G {\n%s}\n", $dotSyntax);
    }
672852
public function createDatabase()
    {
        try {
            $dsn = 'mysql:host=' . $this->host . ';';
            $options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
            $connect = new \PDO($dsn, $this->user, $this->pass, $options);
            $connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

            $command = $connect->prepare("CREATE DATABASE {$this->database}");
            $command->execute();

        } catch (\PDOException $e) {
            return false;
        }
    }
941182
private function loadLanguageData(string $language = 'de')
  {
    if (\in_array($language, self::$availableLanguages, true) === false) {
      throw new StopWordsLanguageNotExists('language not supported: ' . $language);
    }

    $this->stopWords[$language] = $this->getData($language);
  }
641563
protected function createPDOMySQL($location, $database, $username, $password, $errorMode, $charset)
    {
        $dsn = 'mysql:host=' . $location . ';dbname=' . $database;
        if ($charset !== null) {
            $dsn .= ';charset=' . $charset;
        }

        $db  = new \Parable\ORM\Database\PDOMySQL($dsn, $username, $password);
        $db->setAttribute(\PDO::ATTR_ERRMODE, $errorMode);

        return $db;
    }
1252436
public function save(string $table, array $data): array
    {
        try {
            $this->db->beginTransaction();

            $query = "INSERT INTO $table (" .
                implode(', ', array_keys($data)) .
                ") VALUES (" .
                substr(str_repeat(', ?', count($data)), 1) .
                ")" .
                " ON DUPLICATE KEY UPDATE " .
                implode('=?, ', array_keys($data)) . "=?";

            $duplicateDate = array_merge(array_values($data), array_values($data));
            /** @var PDOStatement $stmt */
            $stmt = $this->db->prepare(
                $query
            );
            $stmt->execute(array_values($duplicateDate));
            $this->db->commit();

            return $data;
        } catch (PDOException $e) {
            $this->db->rollBack();
            throw new PDOException($e);
        }
    }