Export from an SQL query to CSV

Hello community yii

I want to create a button that its function is that by pressing it I throw the data of the SQL query into a CSV file to then manually upload the file to the application table yii2

I would appreciate your great help