Make sure there are no reserved words in param names...
@param string $sql
@param array $params
@return array ($sql, $params) updated query and parameters
515212
protected function tweak_param_names($sql, array $params) {
        if (empty($params)) {
            return array($sql, $params);
        }

        $newparams = array();
        $searcharr = array(); // search => replace pairs
        foreach ($params as $name => $value) {
            // Keep the name within the 30 chars limit always (prefixing/replacing)
            if (strlen($name) <= 28) {
                $newname = 'o_' . $name;
            } else {
                $newname = 'o_' . substr($name, 2);
            }
            $newparams[$newname] = $value;
            $searcharr[':' . $name] = ':' . $newname;
        }
        // sort by length desc to avoid potential str_replace() overlap
        uksort($searcharr, array('oci_native_moodle_database', 'compare_by_length_desc'));

        $sql = str_replace(array_keys($searcharr), $searcharr, $sql);
        return array($sql, $newparams);
    }
18591
public function getOne($sql, $params = [])
    {
        if ($sql instanceof Criteria\Criteria) return $this->getOne($sql->toSQL(), $sql->getParams());

        $sth = $this->query($sql, $params, Database::TARGET_SLAVE);
        $row = $sth->fetch(Connection::FETCH_NUM);
        $sth->closeCursor();
        return $row[0];
    }
417998
private function addSelect($sql, array $params = [])
    {
        $this->values = [];

        $this->select = [
            'sql'    => $sql,
            'params' => $params,
        ];

        return $this;
    }
900640
public function getOne($sql = null,$params = array())
	{
		if(!isset($this->operationOption['params']))
		{
			$this->operationOption['params'] = array();
		}
		$this->prepareQuery($sql ? $sql : $this->buildSelectSQL(),$params);
		if(false === $this->lastStmt)
		{
			return false;
		}
		else
		{
			return $this->lastStmt->fetch(PDO::FETCH_ASSOC);
		}
	}
420754
public function sqlFetch(string $sql, array $params = []): ?array
    {
        return $this->prepare($sql, $params)->fetch(\PDO::FETCH_ASSOC);
    }
76473
public function fetchAll(string $sql, array $params = []) : array
    {
        $result = $this->query($sql, $params, true);

        $return = [];

        foreach ($result as $item) {
            $return[] = $item;
        }

        return $return;
    }
670205
private function _queryPDO($sql, array $params = array())
    {
        try {
            $this->_queryId = self::$_linkId->prepare($sql);
            $i = 1;
            foreach ($params as $key => $val) {
                $type = $this->getPDOConstantType($val);
                $this->_queryId->bindValue($i, $val, $type);
                ++$i;
            }
            return $this->_queryId->execute();
        } catch (PDOException $e) {
            $this->_error = $e->getMessage();
            return false;
        }
    }
537515
function execQueryString($sql, $params = null)
    {
        if (!is_array($params) && !is_null($params)) {
            $params = array($params);
        }

        $stmt = $this->prepare($sql);
        $stmt->execute($params);
        return $stmt;
    }
555583
protected function fetch( $sql, $params = null ) {
		$stmt = $this->dbh->prepare( $sql );
		$this->bind( $stmt, $params );
		$stmt->execute();
		return $stmt->fetch();
	}
1147663
public function rawQuery(string $sql, array $params=[]): array
  {
    $rows = [];

    # Sanity check
    if (empty($sql)) {
      return $rows;
    }

    # Obtain transaction, unelss already in a transaction
    $autoCommit = $this->beginTransaction();

    # Prepare
    if ($sth = $this->prepare($sql)) {

      # Binds
      foreach ($params as $bind=>$value) {
        $sth->bindValue( ':'.\ltrim($bind,':'), $value);
      }

      # Execute statement
      if ($sth->execute()) {
        $rows = $sth->fetchAll(\PDO::FETCH_ASSOC);
      }

      # Close the cursor
      $sth->closeCursor();
    }

    # If we had a loacl transaction, commit it
    if ($autoCommit) $this->commit();

    return $rows;
  }
686312
public function prepare(string $sql, array $params = []): Statement
    {
        if (!$stmt = $this->connection->prepare($sql)) {
            $error = [
                'error' => $this->connection->error,
                'errno' => $this->connection->errno,
                'sqlstate' => $this->connection->sqlstate
            ];

            throw new SqlException('Failed to prepare statement', [$error], $sql, $params);
        }

        if (!empty($params)) {
            if (!$stmt->bind_param(self::getMysqlParamTypes($params), ...$params)) {
                throw new SqlException('Failed to bind params', $stmt->error_list, $sql, $params);
            }
        }

        return new Statement($stmt, $this->usedPrepare, $sql, $params);
    }
594619
public function command(string $sql, array $params = [])
    {
        return $this->execute($this->prepare($sql, $params));
    }
184437
public function orderByRaw(string $sql, string ...$params)
    {
        $instance = $this->orderByStrategyInstance();

        $instance->orderByStrategy()->orderByRaw($sql, ...$params);

        return $instance;
    }
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;
    }
205805
public function sqlExecute(string $sql, array $params = []): int
    {
        return $this->prepare($sql, $params)->rowCount();
    }
786722
public function sql(string $sql, array $params = []) {
        return $this->loadWiths($this->modelManager->sql($sql, $params));
    }
167015
public function order(string $sql, array $params = []) : self
    {
        $this->qiterator = null;
        $name = null;
        if (!count($params)) {
            $name = preg_replace('(\s+(ASC|DESC)\s*$)i', '', $sql);
            try {
                $name = $this->getColumn(trim($name))['name'];
            } catch (\Exception $e) {
                $name = null;
            }
        }
        $this->order = [ $sql, $params, $name ];
        return $this;
    }