Prado\Data\TDbCommand::queryScalar PHP Method

queryScalar() public method

This is a convenient method of {@link query} when only a single scalar value is needed (e.g. obtaining the count of the records).
public queryScalar ( ) : mixed
return mixed the value of the first column in the first row of the query result. False is returned if there is no value.
    public function queryScalar()
    {
        try {
            // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'Prado\Data');
            if ($this->_statement instanceof PDOStatement) {
                $this->_statement->execute();
            } else {
                $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText());
            }
            $result = $this->_statement->fetchColumn();
            $this->_statement->closeCursor();
            if (is_resource($result) && get_resource_type($result) === 'stream') {
                return stream_get_contents($result);
            } else {
                return $result;
            }
        } catch (Exception $e) {
            throw new TDbException('dbcommand_query_failed', $e->getMessage(), $this->getDebugStatementText());
        }
    }