@deprecated since Moodle 3.6 MDL-52953 - Please use supported log stores such as "standard" or "external" instead.
@todo MDL-52805 This will be removed in Moodle 4.0

@param  string $selectwhere
@param  array  $params
@return int
516107
public function get_events_select_count($selectwhere, array $params) {
        global $DB;

        // Replace the query with hardcoded mappings required for core.
        list($selectwhere, $params) = self::replace_sql_legacy($selectwhere, $params);

        try {
            return $DB->count_records_select('log', $selectwhere, $params);
        } catch (\moodle_exception $ex) {
            debugging("error converting legacy event data " . $ex->getMessage() . $ex->debuginfo, DEBUG_DEVELOPER);
            return 0;
        }
    }
1199238
public static function count($where = null): int
    {
        $select = static::select();

        if ($where !== null) {
            if ($where instanceof Where) {
                $select->field('COUNT(*)', 'total');
                $select->where(clone $where);

            } else if (is_array($where)) {
                $select->field('COUNT(*)', 'total');
                foreach ($where as $field => $value) {
                    $select->where($field, $value);
                }

            } else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
                $select->field('COUNT(' . static::$primaryKey . ')', 'total');
                $select->where(static::$primaryKey, $where);

            }
        } else {
            $pk = is_string(static::$primaryKey) ? static::$primaryKey : '*';
            $select->field('COUNT(' . $pk . ')', 'total');
        }

        $results = $select->fetchAll();

        if (isset($results[0])) {
            $r = $results[0];
            if (array_key_exists('total', $r)) {
                return (int)$r['total'];
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
1007080
public function executeSelect($tableName, $columns = '*', $where = null, $afterWhere = '')
    {
        list($where, $params) = $this->_buildWhere($where);
        $query = "SELECT $columns FROM $tableName $where $afterWhere";
        if (!($stmt = $this->prepare($query))) {
            return false;
        }
        $stmt->execute($params);
        return $stmt;
    }
209581
public static function _count ($params = array (), &$db = FALSE)
	{
		
		// Remove order

		if (isset ($params['orderby']))
		{
			unset ($params['orderby']);
		}
		
		// Remove limit

		if (isset ($params['limit']))
		{
			unset ($params['limit']);
		}

		// Select count

		$params['select'] = 'COUNT(*)';
		
		// Return
		
		return static::_getValue ($params, \PDO::FETCH_ASSOC, $db);

	}
802758
public final function count(string $query = null, array $queryParams = null): ?int
    {
        $queryBuilder = new QueryBuilder($this->db->getLink());
        $queryBuilder->setTable($this->table);

        if ($query || $queryParams) {
            $queryBuilder->where($query, $queryParams);
        }

        return $queryBuilder->count();
    }
317456
public int execSelectCount(Class<? extends D6Model> modelClazz, WhereCondition whereCondition) {

    final D6CrudSelectHelper d6CrudSelectHelper = new D6CrudSelectHelper(modelClazz);
    final String sqlForSelectCount = d6CrudSelectHelper.getSQLForSelectCount();

    String sql = sqlForSelectCount + " " + whereCondition.toSql();

    return execSelectCount(sql);
  }
338856
protected function _where(Kwf_Db_Table_Select $select, $where)
    {
        $where = (array) $where;

        foreach ($where as $key => $val) {
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $select->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition
                $select->where($key, $val);
            }
        }

        return $select;
    }
349281
public function select($query, array $params = [], $fetchMode = null)
    {
        // Execute query
        $stmt = $this->connection->prepare($query);
        $stmt->execute($params);
        if ($fetchMode !== null) {
            $stmt->setFetchMode($fetchMode);
        }
        return $stmt->fetchAll();
    }
691572
public function rows($column = '*', $where = null, $params = []) {

		if(null === $this -> getAdapter()) {
			return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
		}

		if(false === is_string($column)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($column)), E_USER_ERROR);
		}

		if(null !== $where && false === is_string($where)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($where)), E_USER_ERROR);
		}

		if(false === is_array($params)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
		}

		$query  = [];

		//Select
		$query[] = sprintf('SELECT COUNT(%s) AS amount FROM %s', $this -> getAdapter() -> escape($column), $this -> getAdapter() -> escape($this -> getTable()));

		//Where
		if(null !== $where) {
			$query[] = sprintf('WHERE %s', $this -> getAdapter() -> escape($where));
		}

		$statement = $this -> getAdapter() -> query(implode(' ', $query), $params) -> execute();

		if(true === $statement) {

			$amount = $this -> getAdapter() -> toArray();

			if(true === isset($amount[0]['amount'])) {
				return $amount[0]['amount'];
			}
		}

		return false;
	}
899397
public function select($tableName, $where = null, $afterWhere = '')
    {
        $stmt = $this->executeSelect($tableName, '*', $where, $afterWhere);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
704974
private function addConditionsToSqlWhithWhereIn(): string
    {
        if (count($this->wheresIn) === 0) {
            throw new OrmException('Argument 2 passed to "whereIn()" can not be an empty array.');
        }
        
        $paramsWhereIn = " ( ";

        foreach ($this->wheresIn as $value) {                
            $paramsWhereIn .= " ?, ";

            $this->wheresBindValue[] = $value;
        }

        $this->wheresIn = [];

        return rtrim($paramsWhereIn, ', ')." ) ";
    }
506626
protected function count_button_rows(array &$params) {
        $maxrow = 1;
        foreach ($params as $key => $value) {
            if (preg_match('/^theme_advanced_buttons(\d+)$/', $key, $matches) &&
                    (int)$matches[1] > $maxrow) {
                $maxrow = (int)$matches[1];
            }
        }
        return $maxrow;
    }
68860
public static function getQueryWhere($request, $query, $parameters)
    {
        $indexColumns   = isset($parameters['indexColumns'])? $parameters['indexColumns'] : null;
        $where          = isset($parameters['where'])? $parameters['where'] : null;
        $whereColumns   = isset($parameters['whereColumns'])? $parameters['whereColumns'] : null;
        
        if($where != null)
        {
            $columns = $request->input('columns');

            $query->where(function($query) use ($columns, $indexColumns, $where){
                $i=0;
                foreach($indexColumns as $indexColumn)
                {
                    // check if column if is searchable
                    if($columns[$i]['searchable'] === 'true')
                    {
                        if(is_array($indexColumn)) $indexColumn = $indexColumn['data'];
                        
                        $query->orWhere($indexColumn, 'LIKE', '%' . $where . '%');
                    }
                    $i++;
                }
            });
        }

        if(is_array($whereColumns))
        {
            $query->where(function($query) use ($whereColumns) {
                foreach($whereColumns as $whereColumn)
                {
                    // enable option to be null value, with NULL
                    if($whereColumn['value'] == 'NULL')
                        $whereColumn['value'] = null;

                    $query->where($whereColumn['column'], $whereColumn['operator'], $whereColumn['value']);
                }
            });
        }

        return $query;
    }
675001
public function andWhere($conditions, array $bindParams = null, array $bindTypes = null) {
        if(!is_null($bindParams)) {
            $tmpBindParams = array();
            foreach($bindParams as $key => $value) {
                if(is_int($key)) {
                    $param = 'criteriaHelper' . $this->incrementLocalParamCount();
                    $tmpBindParams[$param] = $value;
                    $conditions = str_replace('?' . $key, ':' . $param . ':', $conditions);
                } else {
                    $tmpBindParams[$key] = $value;
                }
            }
            $bindParams = $tmpBindParams;
        }
        $this->getCriteria()->andWhere($conditions, $bindParams, $bindTypes);
        return $this;
    }
1093274
protected function buildSelectQuery(SQLSelect $query, array &$parameters)
    {
        $sql  = $this->buildSelectFragment($query, $parameters);
        $sql .= $this->buildFromFragment($query, $parameters);
        $sql .= $this->buildWhereFragment($query, $parameters);
        $sql .= $this->buildGroupByFragment($query, $parameters);
        $sql .= $this->buildHavingFragment($query, $parameters);
        $sql .= $this->buildOrderByFragment($query, $parameters);
        $sql .= $this->buildLimitFragment($query, $parameters);
        return $sql;
    }
125600
public function loadCount($params=array()) {
		
		$this->openConnection();
		
		$res = 0;
		
		try {
		
			$stat = $this->handler->prepare($this->query);
			$stat->execute((array)$params);
			$res = (int)$stat->fetch(\PDO::FETCH_COLUMN);

			// logger
			$this->logParamQuery($this->query, $res, $params);
		
		} catch (\PDOException $e) {
		
			$this->handleException($e, $params);
		
		}
		
		$stat->closeCursor();

		return $res;
		
	}
205805
public function sqlExecute(string $sql, array $params = []): int
    {
        return $this->prepare($sql, $params)->rowCount();
    }