@param string $sql
@param array  $params

@return string[]
420754
public function sqlFetch(string $sql, array $params = []): ?array
    {
        return $this->prepare($sql, $params)->fetch(\PDO::FETCH_ASSOC);
    }
343621
public static function getSqlWithParams(string $sql, array $params = []): string
    {
        if (! empty($params)) {
            $indexed = ($params === array_values($params));
            foreach ($params as $k => $v) {
                if (is_string($v)) {
                    $v = "'${v}'";
                }
                if (is_array($v)) {
                    $v = "'" . implode("','", $v) . "'";
                }
                if ($indexed) {
                    $sql = preg_replace('/\?/', $v, $sql, 1);
                } else {
                    $sql = str_replace(":${k}", $v, $sql);
                }
            }
        }

        return str_replace(PHP_EOL, '', $sql);
    }
380950
public static function exec($sql, $params = [])
    {
        BLLog::log('[SQL] ' . $sql);
        BLLog::log('[Params] ' . var_export($params, true));
        $stmt = self::getHandle()->prepare($sql);
        $stmt->execute($params);
        return $stmt;
    }
752911
public function createCommand($sql = null, $params = [])
    {
        $command = new Command([
            'db' => $this,
            'sql' => $sql,
        ]);

        return $command->bindValues($params);
    }
917965
public function sqlFetchPairs(string $sql, array $params = [], string $key = '0', string $value = '1'): array
    {
        $stmt = $this->prepare($sql, $params);

        $pairs = [];

        while ($record = $stmt->fetch()) {
            $pairs[array_key_exists($key, $record) ? $record[$key] : null] = array_key_exists($value, $record) ? $record[$value] : null;
        }

        return $pairs;
    }
748812
public function findAllBySql($sql,$params=array())
	{
		Yii::trace(get_class($this->_joinTree->model).'.findAllBySql() eagerly','system.db.ar.CActiveRecord');
		if(($rows=$this->_builder->createSqlCommand($sql,$params)->queryAll())!==array())
		{
			$baseRecords=$this->_joinTree->model->populateRecords($rows,false);
			$this->_joinTree->findWithBase($baseRecords);
			$this->_joinTree->afterFind();
			$this->destroyJoinTree();
			return $baseRecords;
		}
		else
		{
			$this->destroyJoinTree();
			return array();
		}
	}
1155792
public function getValue($sql, $params = null)
    {
        $stmt = $this->execute($sql, $params);

        return $stmt->fetchColumn(0);
    }
226221
public function query(string $sql, array $params = []) {
        X::logger()->trace("$sql with params " . $this->serializeArray($params));
        try {
            $st = $this->pdo->prepare($sql);
            if ($st === false) {
                $e = $this->pdo->errorInfo();
                throw new DataBaseException($e[2], $e[1]);
            }
            if ($st->execute($params)) {
                $this->_affectedRows = $st->rowCount();
                $this->_lastInsertId = $this->pdo->lastInsertId();
                return $st->fetchAll(PDO::FETCH_ASSOC);
            }

            $e = $st->errorInfo();
            throw new DataBaseException($e[2], $e[1]);
        } catch (PDOException $ex) {
            X::logger()->trace($ex);
            throw new DataBaseException($ex->getMessage(), $ex->getCode());
        }
    }
1185988
protected function fetchAll( $sql, $params = null ) {
		$this->logger->debug( $sql, $params ?: [] );
		$stmt = $this->dbh->prepare( $sql );
		$this->bind( $stmt, $params );
		$stmt->execute();
		return $stmt->fetchAll();
	}
970842
public function groupByRaw(string $sql, string ...$params)
    {
        $instance = $this->groupByStrategyInstance();

        $instance->groupByStrategy()->groupByRaw($sql, ...$params);

        return $instance;
    }
280397
private function getFinalQuery(string $sql, array $params = []) : string
    {
        if (sizeof($params) == 0 || is_numeric(array_keys($params)[0])) {
            return $sql;
        }

        $split = preg_split('`([\\:\\!][A-Za-z0-9]+)`', $sql, -1, PREG_SPLIT_DELIM_CAPTURE);

        foreach ($split as $index => $item) {
            if (substr($item, 0, 1) == ':') {
                // ! is for unquote values
                $name = substr($item, 1);
                if (!array_key_exists($name, $params)) {
                    throw new QueryException(
                        $this,
                        $sql,
                        sprintf("Missing parameters '%s'", $name)
                    );
                }

                $split[$index] = $this->escape($params[$name]);
            } elseif (substr($item, 0, 1) == '!') {
                // ! is for unquote values
                $name = substr($item, 1);
                if (!array_key_exists($item, $params)) {
                    throw new QueryException(
                        $this,
                        $sql,
                        sprintf("Missing parameters '%s'", $name)
                    );
                }

                $split[$index] = $params[$item];
            }
        }

        return implode('', $split);
    }
690890
public function sqlFetchAllColumn(string $sql, array $params = [], string $column = '0'): array
    {
        $stmt = $this->prepare($sql, $params);

        if (ctype_digit((string) $column)) {
            return $stmt->fetchAll(\PDO::FETCH_COLUMN, $column);
        }

        $values = [];

        while ($record = $stmt->fetch()) {
            $values[] = array_key_exists($column, $record) ? $record[$column] : null;
        }

        return $values;
    }
976336
public function debugQuery($sql, $params = array())
    {
        $keys = array();

        # build a regular expression for each parameter
        foreach ($params as $key => &$value)
        {
            if (is_string($key))
            {
                $keys[] = '/:' . $key . '/';
            }
            else
            {
                $keys[] = '/[?]/';
            }
            $value = '[#' . $value . '#]';
        }

        $query = preg_replace($keys, $params, $sql, 1, $count);

        return $query;
    }
325531
public function query($sql, $params = [], $options = [])
    {
        $conn = $this->getConn(!empty($options['forceMaster']) ? true : false);

        $stmt = $this->prepare($conn, $sql, $params);

        $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        if ($rows === false) {
            $this->throwException();
        }
        if (!empty($options['getRow'])) {
            $rows = isset($rows[0]) ? $rows[0] : null;
        }
        return $rows;
    }
1287492
public function setSql($sql, array $params = [])
    {
        $this->sql = (string) $sql;

        $this->setSqlParameters($params);
    }
526642
public static function raw(
        $sql,
        $params = null
    ) {
        $results = static::getDatabase()->getResults($sql, $params);

        return $results;
    }
960872
private function selectQuery($sql, array $params = array())
    {
        $stmt = $this->getConnection()->prepare($sql);
        $stmt->execute($params);

        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }