/** * @param string|\yii\db\ActiveQuery $sql * @param array $params * @return array */ public static function queryHash($sql, $params = []) { if ($sql instanceof ActiveQuery) { $query = $sql->asArray()->all(); } else { $query = \Yii::$app->db->createCommand($sql)->query($params); } $result = []; foreach ($query as $row) { $row = array_values($row); $result[$row[0]] = $row[1]; } return $result; }