can not create file,console app,yii2

I am trying to make a back-up from a table with the bellow code (command line action) but I have the error can not create/write to file and the \Yii::$app->basePath is not well formated: cxampphttdocsfront and not c:/xampp/httdocs/front at the command line error how can I find the "web: folder at console apps?


public function actionOut() {

        $tableName  = 'medication';

$backupFile = \Yii::$app->basePath.'/patients/yourtable.sql';

$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";

Yii::$app->db->createCommand($query)

   ->execute();

    }

}

This should work (you may have to add "use Yii;")


$backupFile = Yii::$app->basePath.'/patients/yourtable.sql';

The file goes to your chosen subdir under the app root (where the yii script is).

The subdir needs write permission and you may have to handle the "–secure-file-priv option" (mySql/MariaDB).

This worked at windows with xampp server.


$tableName  = 'country';

$backupFile =  str_replace("\\",'/',Yii::$app->basePath).'/web/patients/'.date('Y-m-d_H_m_s').'.sql';

$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";

Yii::$app->db->createCommand($query)

  ->execute();