yii\db\Query::one PHP Méthode

one() public méthode

Executes the query and returns a single row of result.
public one ( Connection $db = null ) : array | boolean
$db Connection the database connection used to generate the SQL statement. If this parameter is not given, the `db` application component will be used.
Résultat array | boolean the first row (in terms of an array) of the query result. False is returned if the query results in nothing.
    public function one($db = null)
    {
        if ($this->emulateExecution) {
            return false;
        }
        return $this->createCommand($db)->queryOne();
    }

Usage Example

Exemple #1
2
 public static function mostPopular()
 {
     $query = new Query();
     $query->select('meme_id, COUNT(meme_id) AS n_memes')->from('meme_vidmage')->groupBy('meme_id')->orderBy(['n_memes' => SORT_DESC])->limit(1);
     $row = $query->one();
     return self::findOne($row['meme_id']);
 }
All Usage Examples Of yii\db\Query::one