Creates a new InsertQueryBuilder instance.

@param string $connectionName
@return InsertQueryBuilder
@throws DatabaseException
481367
public function makeInsert(string $connectionName = ''): InsertQueryBuilder
    {
        $connection = $this->provideConnection($connectionName);
        $statementBuilder = new InsertStatementBuilder;
        return new InsertQueryBuilder($connection, $statementBuilder);
    }
45390
public function newFromBuilder($attributes = [], $connection = null)
    {
        // Create Instance
        $manager = app(OptionManager::class);
        $type = array_get((array) $attributes, 'type');
        $entity = $type ? $manager->findByNamespace($type) : null;
        $model = $entity ? $entity->newInstance([], true) : $this->newInstance([], true);

        $model->setRawAttributes((array) $attributes, true);
        $model->setConnection($connection ?: $this->getConnectionName());
        $model->fireModelEvent('retrieved', false);

        return $model;
    }
849197
protected function newBaseQueryBuilder()
    {
        $connection = $this->getConnection();

        return new QueryBuilder($connection, $connection->getQueryGrammar(), $connection->getPostProcessor());
    }
536905
final public static function getDbInstance(string $databaseName = '#none'):\PDO
    {
        if (self::$co_instance == null) {
            new self($databaseName);
        }
        return (self::$co_instance);
    }
768796
public function getConnection(string $connectionName): \PDO
    {
        if (!isset($this->connections[$connectionName])) {
            throw new DatabaseException(sprintf('Connection (%s) not found in pool.', $connectionName));
        }
        return $this->connections[$connectionName];
    }
66841
public function create_database($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null) {
        $driverstatus = $this->driver_installed();

        if ($driverstatus !== true) {
            throw new dml_exception('dbdriverproblem', $driverstatus);
        }

        if (!empty($dboptions['dbsocket'])
                and (strpos($dboptions['dbsocket'], '/') !== false or strpos($dboptions['dbsocket'], '\\') !== false)) {
            $dbsocket = $dboptions['dbsocket'];
        } else {
            $dbsocket = ini_get('mysqli.default_socket');
        }
        if (empty($dboptions['dbport'])) {
            $dbport = (int)ini_get('mysqli.default_port');
        } else {
            $dbport = (int)$dboptions['dbport'];
        }
        // verify ini.get does not return nonsense
        if (empty($dbport)) {
            $dbport = 3306;
        }
        ob_start();
        $conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); // Connect without db
        $dberr = ob_get_contents();
        ob_end_clean();
        $errorno = @$conn->connect_errno;

        if ($errorno !== 0) {
            throw new dml_connection_exception($dberr);
        }

        // Normally a check would be done before setting utf8mb4, but the database can be created
        // before the enviroment checks are done. We'll proceed with creating the database and then do checks next.
        $charset = 'utf8mb4';
        if (isset($dboptions['dbcollation']) and (strpos($dboptions['dbcollation'], 'utf8_') === 0
                || strpos($dboptions['dbcollation'], 'utf8mb4_') === 0)) {
            $collation = $dboptions['dbcollation'];
            $collationinfo = explode('_', $dboptions['dbcollation']);
            $charset = reset($collationinfo);
        } else {
            $collation = 'utf8mb4_unicode_ci';
        }

        $result = $conn->query("CREATE DATABASE $dbname DEFAULT CHARACTER SET $charset DEFAULT COLLATE ".$collation);

        $conn->close();

        if (!$result) {
            throw new dml_exception('cannotcreatedb');
        }

        return true;
    }
883979
public function query($query = null)
    {
        /** @var StmtInterface $result */
        try {
            
            $event = new ConnectionEvent($this, $query);
            $this->container->getDispatcher()->dispatch(ConnectionEvent::ON_QUERY, $event);
            
            $result = parent::query($query);
        } catch (\Exception $exception) {
            throw new ConnectionException(sprintf(
                'Executing SQL Query was failure with error: [%d] (%s)', $exception->getCode(), $exception->getMessage()));
        }
        
        return $result;
    }
799818
protected function newBaseQueryBuilder()
    {
        $conn = $this->getConnection();

        $grammar = $conn->getQueryGrammar();

        $builder = new Builder($conn, $grammar, $conn->getPostProcessor());
        $builder->cacheDriver($this->cache);

        if ($this->expire !== null) {
            $builder->remember($this->expire);
        }

        $builder->cacheTags($this->table);

        return $builder;
    }
225467
private function slaveQueryBuilder()
    {
        /** @var Connection $connection */
        $connection = $this->em->getConnection();
        if ($connection instanceof MasterSlaveConnection) {
            // Prefer a slave connection if available.
            $connection->connect('slave');
        }

        return new QueryBuilder($connection);
    }
772250
public function create(array $data, $databaseConnectionName = null)
  {
    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    $File = new File();
    $File->setConnection($databaseConnectionName);
    $File->fill($data)->save();

    return $File;
  }
1222900
public function newFromBuilder($attributes = array(), $connection = null)
    {
        // hide ref_id from model, because ref_id == id
        $attributes = array_except((array) $attributes, $this->getVersionKeyName());

        return parent::newFromBuilder($attributes, $connection);
    }
529643
private function buildBaseQuery(
        Connection $connection,
        TableMetadata $tableMetadata,
        string $searchTerm
    ): QueryBuilder {

        // Build query except WHERE clause
        $queryBuilder = $connection
            ->createQueryBuilder()
            ->select('COUNT(*) AS count')
            ->from('`' . $tableMetadata->getDatabaseName() . '`.`' . $tableMetadata->getTableName() . '`')
            ->setParameter('search_term', '%' . $searchTerm . '%');

        foreach ($this->getSearchableColumnNames($tableMetadata) as $index => $columnName) {
            $clause = '`' . $columnName . '` LIKE :search_term';
            if (0 === $index) {
                $queryBuilder->where($clause);
            } else {
                $queryBuilder->orWhere($clause);
            }
        }

        return $queryBuilder;
    }
1299367
public function create(array $data, $databaseConnectionName = null)
  {
    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    $ApportionmentEntry = new ApportionmentEntry();
    $ApportionmentEntry->setConnection($databaseConnectionName);
    $ApportionmentEntry->fill($data)->save();

    return $ApportionmentEntry;
  }
572489
public static MySqlConnectionPoolBuilder newBuilder(final String connectionString, final String username) {
    final String[] arr = connectionString.split(":");
    final String host = arr[0];
    final int port = Integer.parseInt(arr[1]);
    return newBuilder(host, port, username);
  }
607180
public static function create($connectionURI) {
    $connection = new MongoDataConnection();
    $database = parse_url($connectionURI, PHP_URL_PATH);
    $database = ltrim($database, '/');
    $mongo = new \MongoClient($connectionURI);
    $connection->db = $mongo->selectDB($database);

    return $connection;
  }
892618
private static function createForConnection($name)
    {
        $config = &self::$config['connection'][$name];

        switch ($config['type']) {
            case Type::MYSQL:
                return new Concrete\MySQL(new Concrete\MySQL\Connection(
                    $config['host'],
                    $config['user'],
                    $config['password'],
                    $config['database'],
                    $config['persistent']
                ));
            case Type::POSTGRESQL:
            default:
                throw new DbException("can`t create database: this db type (${config['type']}) not supported");
        }
    }
788572
public function addQuery($query, $connectionName = 'default')
    {
        $queryData = [
            $query['time'] / 1000,
            $query['query'],
            $query['bindings']
        ];
        $this->queriesByConnection[$connectionName][] = $queryData;
        if (!isset($this->totalQueriesTimeByConnection[$connectionName])) {
            $this->totalQueriesTimeByConnection[$connectionName] = 0;
        }
        $this->totalQueriesTimeByConnection[$connectionName] += $query['time'] / 1000;
        return $this;
    }