Returns COUNT()

@param mixed $col [optional]
@param mixed $where [optional]
@return int
972111
public function getCount($col = null, $where = true)
    {
        if ($this->map) {
            $where = $this->map->where($where);
        }
        if ($this->fake) {
            return $this->fake->getCount($col, $where);
        }
        if ($col !== null) {
            $p = '?c';
            if ($this->map) {
                $col = $this->map->col($col);
            }
        } else {
            $p = '?q';
            $col = 1;
        }
        $pattern = 'SELECT COUNT('.$p.') FROM ?t WHERE ?w';
        $data = array($col, $this->name, $where);
        return $this->db->query($pattern, $data)->el();
    }
431514
public function count()
    {
        $this->countQuery->execute();
        $res = $this->countQuery->fetchColumn();
        $this->countQuery->closeCursor();
        return (int) $res;
    }
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;
        }
    }
877341
public function countBySubQuery($conditions = false)
    {
        $this->andWhere($conditions);
        return (int)$this->db->fetchColumn($this->getSqlForCount(), $this->params);
    }
956059
private function _count($method, $column = NULL)
    {
        $this->options['limit']['0'] = 1;
        if($method == 'distinct')
            if(is_null($column)) // 默认id
                $this->options['field']['0'] = 'count(' . $method . ' `' . $this->key . '`) as count';
            else
                $this->options['field']['0'] = 'count(' . $method . ' `' . $column . '`) as count';
        elseif(is_null($column) && $method == 'count') // 默认*
            $this->options['field']['0'] = $method . '(*) as count';
        elseif($column)
            $this->options['field']['0'] = $method . '(`' . $column . '`) as count';
        else // 默认id
            $this->options['field']['0'] = $method . '(`' . $this->key . '`) as count';
        $result = $this->query($this->_parseSql(), $this->prepareParam, false);
        return isset($result->count) ? $result->count : 0;
    }
141557
public function delete($table, $where = '')
    {
        $where = $this->_whereExpr($where);

        /**
         * Build the DELETE statement
         */
        $sql = "DELETE FROM "
             . $this->quoteIdentifier($table, true)
             . (($where) ? " WHERE $where" : '');

        /**
         * Execute the statement and return the number of affected rows
         */
        $stmt = $this->query($sql);
        $result = $stmt->rowCount();
        return $result;
    }
1216107
public function getCount($where = '', $variables = null)
    {
        $where = $this->formatWhereClause($where);

        $response = $this->driver->query("select count(*) as numberOfItems from " . $this->getTable() . ' ' . $where . ";", $variables);

        if (!$response->count()) return 0;

        $response = $response->row();

        return intval($response->numberOfItems);
    }
508040
public static function count(string $className, string $column, array $condition): ResultInterface
    {
        $instance = self::getInstance($className);
        $query    = Query::table($className)->selectInstance($instance)->condition($condition);

        return $query->count($column);
    }
1266563
public function countResult($wheres = [], $selectField = '*')
    {
        if (!is_array($selectField)) {
            $selectField = [$selectField];
        }
        $db = $this->db->select($selectField)->from($this->table);
        if (is_array($wheres) && count($wheres) > 0) {
            foreach ($wheres as $field => $value) {
                if (is_array($value)) {
                    $db->whereIn($field, $value);
                } else {
                    $db->where($field, self::OPERATOR_EQUAL_TO, $value);
                }
            }
        } else {
            $db->where($this->primaryKey, self::OPERATOR_EQUAL_TO, $wheres);
        }
        $totalItem = $db->execute()->rowCount();
        $this->debug->debug(__FUNCTION__, 'Total Item Result => ' . json_encode($totalItem));

        return $totalItem;
    }
28215
private function sql_handle_col( $col, $table ) {
		global $wpdb;

		$table_sql = $this->esc_sql_ident( $table );
		$col_sql   = $this->esc_sql_ident( $col );

		$count = $wpdb->query( $wpdb->prepare( "UPDATE $table_sql SET $col_sql = REPLACE($col_sql, %s, %s);", $this->old, $this->new ) );

		return $count;
	}
541384
public function countResult($wheres = [], $selectField = '*')
    {
        if (is_array($wheres) && count($wheres) > 0) {
            foreach ($wheres as $field => $value) {
                if (is_array($value)) {
                    $this->db->where($field, $value, self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($field, $value, self::OPERATOR_EQUAL_TO);
                }
            }
        } else {
            $this->db->where($this->primaryKey, $wheres, self::OPERATOR_EQUAL_TO);
        }
        $result = $this->db->get($this->table, NULL, $selectField);
        $this->debug->debug(__FUNCTION__, 'Total Item Result => ' . json_encode($result));
        if ($this->db->count > 0) {
            return (int) $this->db->count;
        }

        return 0;
    }
599284
public function countResult($wheres = [], $selectField = '*')
    {
        if (!is_array($selectField)) {
            $selectField = [$selectField];
        }
        $this->connection();
        $db = DB::table($this->table);
        if (is_array($wheres) && count($wheres) > 0) {
            foreach ($wheres as $field => $value) {
                if (is_array($value)) {
                    $db->whereIn($field, $value);
                } else {
                    $db->where($field, self::OPERATOR_EQUAL_TO, $value);
                }
            }
        } else {
            if (is_array($wheres)) {
                $db->whereIn($this->primaryKey, $wheres);
            } else {
                $db->where($this->primaryKey, self::OPERATOR_EQUAL_TO, $wheres);
            }
        }
        $this->debug->debug(__FUNCTION__, 'SQL Queries: ' . $db->toSql());
        $result = $db->get($selectField);
        $this->debug->debug(__FUNCTION__, 'Format is get all Result => ' . json_encode($result));
        $totalItem = $result->count();
        $this->debug->debug(__FUNCTION__, 'Total Item Result => ' . json_encode($totalItem));

        return $totalItem;
    }
1275674
public int count(Entity where) throws SQLException {
		Connection conn = null;
		try {
			conn = this.getConnection();
			return runner.count(conn, where);
		} catch (SQLException e) {
			throw e;
		} finally {
			this.closeConnection(conn);
		}
	}
650914
public function GetCount($Table = '', $Where = FALSE) {
      if($Table != '') {
         //$this->MapAliases($Table);
         $this->From($Table);
      }

      if ($Where !== FALSE)
         $this->Where($Where);

      $this->Select('*', 'count', 'RowCount'); // count * slow on innodb
      $Sql = $this->GetSelect();
      $Result = $this->Query($Sql);

      $CountData = $Result->FirstRow();
      return $CountData->RowCount;
   }
1326634
public function columnCount()
    {
        if(empty($this->_resultData) || empty($this->_resultData->result)){
            return 0;
        }

        return count(@$this->_resultData->result[0]);
    }
584038
public static function countWhere (string $column, array $operatorValue, string $joinOperator="AND") : int
	{
		$joinOperator 	= static::validateOperator($joinOperator, "AND");
		$expression 	= static::generateValue($column, $operatorValue, $joinOperator);
		$sqlQuery  		= "SELECT COUNT(*) as count FROM ".static::$tableName." WHERE {$column} {$expression}";
		$resultSet 		= Database::getInstance()->query($sqlQuery);
		$row 			= Database::fetchAssoc($resultSet);
		return (int) array_shift($row);
	}
94724
public function count()
    {
        // convert to criteria.
        $criteria = call_user_func_array(array($this, 'argsToCriteria'), func_get_args());

        $criteria->columns('count(1) as c');
        
        // logical delete ?
        $schema = $this->getSchema();
        if ($schema->hasColumn('active')) {
            $criteria->where('active = ?', 1);
        }

        // to SQL.
        $sql = $criteria->toSQL();

        // query
        return $this->getOne($sql, $criteria->getParams());
    }