/** * Set the field to count. * @param $fields * @return $this * @throws FatalException */ public function fields($fields) { if (!is_string($fields)) { throw new FatalException('Only strings are allowed in COUNT query'); } $this->fields = sprintf('COUNT(%s)', DatabaseConnectionFactory::get()->quote($fields)); return $this; }
/** * Execute the query. * * @return DatabaseRecord * @throws FatalException */ public function execute() { if ($this->table === null) { throw new FatalException(sprintf('No table defined for method `%s`.', $this->getQueryType())); } if ($this->queryType === static::MODE_QUERY) { return DatabaseConnectionFactory::get()->query($this); } else { return DatabaseConnectionFactory::get()->execute($this); } }
/** * Override the default execute function. * * @return int Last insert ID. */ public function execute() { $result = parent::execute(); return DatabaseConnectionFactory::get()->lastInsertId(); }