Prepare PDO statement

@return \Ark\Database\QueryBuilder
431436
public function prepare()
    {
        if (null === $this->statement) {
            $this->statement = $this->db->prepare($this->getSql());
        }

        return $this;
    }
166119
public function getPdo() : PDO
    {
        if(empty($this->pdo)) {
            $this->pdo = new PDO("sqlite:".$this->getDir().$this->getFileNames()[0]);
        }
        return $this->pdo;
    }
1168525
public function prepare($statement, $driver_options = [])
    {
        if (!is_null($this->pagination)) {
            $pagination_query = $this->paginateQuery($statement, $this->pagination->getCurrentPageNumber(), $this->pagination->getMaxResultsPerPage());
            $count_query = $this->convertToCountQuery($statement);

            $primary_statement = parent::prepare($pagination_query, $driver_options);
            $count_statement = parent::prepare($count_query, $driver_options);

            $statement = new PdoStatement();
            $statement->setPagination($this->pagination);
            $statement->setPrimaryStatement($primary_statement);
            $statement->setCountStatement($count_statement);

            // clear pagination
            $this->pagination = null;

            return $statement;
        } else {
            return parent::prepare($statement, $driver_options);
        }
    }
968002
public function prepare($sql)
    {
        if (! array_key_exists($sql, $this->statements)) {
            $this->statements[$sql] = $this->pdo->prepare($sql);

        }
        return $this->statements[$sql];
    }
559639
public function prepare($query)
    {
        $this->connect();
        $options = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL];
        $isObject = $query instanceof Query;
        if ($isObject && $query->isBufferedResultsEnabled() === false) {
            $options = [];
        }
        $statement = $this->_connection->prepare($isObject ? $query->sql() : $query, $options);

        return new SqlserverStatement($statement, $this);
    }
641334
public function queryBuilder()
    {
        if (!$this->queryBuilder) {
            $this->queryBuilder = $this->grid->model()->getQueryBuilder();
        }

        return $this->queryBuilder;
    }
175206
public function prepareStatements()
    {
        $addUpdateQuery = '';
        $addInsertQueryFields = '';
        $addInsertQueryValues = '';

        // create vars to keep statements dynamic
        foreach ($this->additionalFields as $value) {
            $addUpdateQuery .= ', ' . $value . ' = ?';
            $addInsertQueryFields .= ', ' . $value;
            $addInsertQueryValues .= ', ?';
        }

        // Statement to check if record already exists in db
        $databaseConnection = Db::getDatabaseConnection('tx_kesearch_index');
        $databaseConnection->exec('PREPARE searchStmt FROM "
			SELECT *
			FROM tx_kesearch_index
			WHERE orig_uid = ?
			AND pid = ?
			AND type = ?
			AND language = ?
			LIMIT 1
		"');

        // Statement to update an existing record in indexer table
        $databaseConnection = Db::getDatabaseConnection('tx_kesearch_index');
        $databaseConnection->exec('PREPARE updateStmt FROM "
			UPDATE tx_kesearch_index
			SET pid=?,
			title=?,
			type=?,
			targetpid=?,
			content=?,
			tags=?,
			params=?,
			abstract=?,
			language=?,
			starttime=?,
			endtime=?,
			fe_group=?,
			tstamp=?' . $addUpdateQuery . '
			WHERE uid=?
		"');

        // Statement to insert a new records to index table
        $databaseConnection = Db::getDatabaseConnection('tx_kesearch_index');
        $databaseConnection->exec('PREPARE insertStmt FROM "
			INSERT INTO tx_kesearch_index
			(pid, title, type, targetpid, content, tags, params, abstract, language,'
            . ' starttime, endtime, fe_group, tstamp, crdate' . $addInsertQueryFields . ')
			VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?' . $addInsertQueryValues . ', ?)
		"');

        // disable keys only if indexer table was truncated (has 0 records)
        // this speeds up the first indexing process
        // don't use this for updating index table
        // if you activate this for updating 40.000 existing records, indexing process needs 1 hour longer
        $queryBuilder = Db::getQueryBuilder('tx_kesearch_index');
        $countIndex = $queryBuilder
            ->count('*')
            ->from('tx_kesearch_index')
            ->execute()
            ->fetchColumn(0);
        if ($countIndex == 0) {
            Db::getDatabaseConnection('tx_kesearch_index')->exec('ALTER TABLE tx_kesearch_index DISABLE KEYS');
        }
    }
58820
public static function ExecuteEach()
	{
		$arguments = func_get_args();
		$executeQueryBuilders = is_array($arguments[0])? $arguments[0] : $arguments;

		$db = self::connect();
		$db->beginTransaction();
		
		try
		{
			$results = null;

			foreach($executeQueryBuilders as $executeQueryBuilder)
			{				
				$executeQuery = $executeQueryBuilder($results);
				$query = $db->prepare($executeQuery["statement"]);
			
				foreach($executeQuery["parameters"] as $key => $parameter)
				{
					if(!isset($parameter["type"]))
						$parameter["type"] = PDO::PARAM_STR;
						
					$query->bindParam($key,$parameter["value"],$parameter["type"]);
				}
					
				$query->execute();
				$rowsAffected = $query->rowCount();
				$lastID = $db->lastInsertId();

				$results = (object) array(
					DatabaseReturn::RowsAffected => $rowsAffected,
					DatabaseReturn::LastInsertID => $lastID
				);
			}
		}
		catch (PDOException $e)
		{
			$db->rollBack();
			$exception = "Sorry, there was a problem with query execution. ({$e->getMessage()})";
		}

		if($exception) throw new \Exception($exception);
		
		$db->commit();
		return $results;
	}
566543
private function getQuerySelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT q.*, qt.*')
            ->from('ngbm_collection_query', 'q')
            ->innerJoin(
                'q',
                'ngbm_collection_query_translation',
                'qt',
                $query->expr()->andX(
                    $query->expr()->eq('qt.query_id', 'q.id'),
                    $query->expr()->eq('qt.status', 'q.status')
                )
            );

        return $query;
    }
879919
public function prepare(string $sql): ?\PDOStatement {
        $statement = $this->getConnection()->prepare($sql);
        if ($statement === false) {
            return null;
        }
        $this->statement = $statement;
        return $statement;
    }
816952
public function execute()
    {
        $stmt = $this->pdo->prepare($this->build());

        if ($stmt->execute($this->getValues())) {
            $this->rowCount = $stmt->rowCount();

            return $stmt;
        } else {
            return false;
        }
    }
857511
private function _prepare()
	{
		if (count($this->_aSelect) > 0 && $this->_aSelect[0] === 'FOUND_ROWS()' && $this->_sFrom === '') {

			$sQuery = 'SELECT FOUND_ROWS()';
		}
		else if (count($this->_aSelect) > 0 && $this->_sFrom !== '') {

			$sQuery = 'SELECT '.implode(',', $this->_aSelect).' FROM `'.$this->_sFrom.'` ';
			$sQuery = str_replace('SQL_CALC_FOUND_ROWS,', 'SQL_CALC_FOUND_ROWS ', $sQuery);

			if ($this->_sFromAs !== null) {

				$sQuery .= 'AS '.$this->_sFromAs.' ';
			}
			else {

				$sQuery .= 'AS t'.$this->_iAlias.' ';
				$this->_sFromAs = 't'.$this->_iAlias;
				$this->_iAlias++;
			}

			$sQuery .= $this->_prepareJoin();
			$sQuery .= $this->_prepareWhere();
			$sQuery .= $this->_prepareGroupBy();
			$sQuery .= $this->_prepareHaving();
			$sQuery .= $this->_prepareOrderBy();
			$sQuery .= $this->_prepareLimit();
		}
		else if ($this->_sUpdate !== '') {

			$sQuery = 'UPDATE `'.$this->_sUpdate.'` ';

			if (count($this->_aSet) > 0) {

				$sQuery .= ' SET ';

				foreach ($this->_aSet as $sKey => $sValue) {

					if ($sValue !== null) {

						$sQuery .= "`".$sKey."` = ".self::connect()->quote($sValue).",";
					}
				}
			}

			$sQuery = substr($sQuery, 0, -1);

			$sQuery .= $this->_prepareWhere();
		}
		else if ($this->_sInsertInto !== '') {

			$sQuery = 'INSERT INTO `'.$this->_sInsertInto.'` (';

			foreach ($this->_aValues as $sKey => $sValue) {

			    if (!is_array($sValue)) { $sQuery .= " `".$sKey."`,"; }
			}

			$sQuery = substr($sQuery, 0, -1);
			$sQuery .= ") VALUES (";

			foreach ($this->_aValues as $sKey => $sValue) {

				if (!is_array($sValue)) { $sQuery .= "".self::connect()->quote($sValue).","; }
			}

			$sQuery = substr($sQuery, 0, -1);
			$sQuery .= ")";
			
			if (count($this->_aOnDuplicateKeyUpdate) > 0) {
			    
			    $sQuery .= " ON DUPLICATE KEY UPDATE ";
			    
    			foreach ($this->_aOnDuplicateKeyUpdate as $sKey => $sValue) {
    			    
    			    $sQuery .= " ".$sKey." = ".self::connect()->quote($sValue).",";
    			}
    			
    			$sQuery = substr($sQuery, 0, -1);
			}
		}
		else if ($this->_sDelete !== '') {

			$sQuery = 'DELETE FROM `'.$this->_sDelete.'`';
			$sQuery .= $this->_prepareWhere();
		}
		else if ($this->_sTruncate !== '') {

			$sQuery = 'TRUNCATE `'.$this->_sTruncate.'`';
		}

		return $sQuery;
	}
577428
protected function getPDO()
    {
        if (null === $this->pdo) {
            $this->pdo = new \PDO($this->dsn, $this->user, $this->password, $this->options);
        }
        return $this->pdo;
    }
492040
public function prepare() {
        $sql = $this->getSql();
        $params = array_merge($this->whereParams(), $this->having_params);
        return [$sql, $params];
    }
258287
protected function getQueryBuilderForDemand(): QueryBuilder
    {
        $queryBuilder = $this->getQueryBuilder();
        $queryBuilder
            ->select('*')
            ->from('sys_redirect')
            ->orderBy('source_host')
            ->addOrderBy('source_path');

        $constraints = [];
        if ($this->demand->hasSourceHost()) {
            $constraints[] =$queryBuilder->expr()->eq(
                'source_host',
                $queryBuilder->createNamedParameter($this->demand->getSourceHost(), \PDO::PARAM_STR)
            );
        }

        if ($this->demand->hasSourcePath()) {
            $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getSourcePath()) . '%';
            $constraints[] = $queryBuilder->expr()->like(
                'source_path',
                $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR)
            );
        }

        if ($this->demand->hasTarget()) {
            $escapedLikeString = '%' . $queryBuilder->escapeLikeWildcards($this->demand->getTarget()) . '%';
            $constraints[] = $queryBuilder->expr()->like(
                'target',
                $queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR)
            );
        }

        if ($this->demand->hasStatusCode()) {
            $constraints[] =$queryBuilder->expr()->eq(
                'target_statuscode',
                $queryBuilder->createNamedParameter($this->demand->getStatusCode(), \PDO::PARAM_INT)
            );
        }

        if (!empty($constraints)) {
            $queryBuilder->where(...$constraints);
        }
        return $queryBuilder;
    }
548897
public function prepare($query, array $bindings=[])
    {
        $statement = $this->statement($query);

        $this->callBeforeListeners('prepare',[$query, $bindings]);

        $prepared = (new PDOPrepared(
            $statement,
            $query,
            $this->getOption(self::RETURN_LAST_AFFECTED),
            $this->errorHandler
        ))->bind($bindings);

        $this->callAfterListeners('prepare',[$query, $bindings, $prepared]);

        return $prepared;

    }
855190
public function buildQuery() 
    {
        $qb = $this->dataGrid->getQueryBuilder();

        if (!$qb instanceof QueryBuilder){
            throw new \InvalidArgumentException('Value must be instance of Doctrine\ORM\QueryBuilder.');
        }
        
        $options = $this->getOptions();
        
        // Is dependant grid ?
        if ($this->dataGrid->isDependentGrid()) {
            $qb->setParameter('masterGridRowId', $options['masterGridRowId']);
        }
        
        // Orders the records
        if ($options['orderBy']) {
            $qb->addOrderBy($options['orderBy'], $options['sort']);
        }
        
        // Applying search filters
        if ($options['search'] && !empty($options['filters'])) {
            $this->applyFilters($qb, $options['filters']);
        }
        
        // dispatch should onQueryBuilderReady event here
        
        if (!$this->dataGrid->isSortableEnabled() && $options['page'] && $options['records']){
            $qb->setMaxResults($options['records']);
            $qb->setFirstResult(($options['page'] - 1) * $options['records']);
        }

        $this->setQuery($qb->getQuery());
        
        // Getting count
        $paginator = new Paginator($this->getQuery());
        //$paginator->setUseOutputWalkers(false);
        $this->setCount($paginator->count());
        
        return $this;
    }