Hi.
I have to write actionInitConfig. I download data from the form, save in the files: @app/config/db.php and @app/config/mailer.php.
I want to open the database and export the structure and preliminary data. I can’t open the database. I tried several ways. Here’s the last way.
$db = new Yii\db\Connection([
'dsn' => 'mysql:host=' . $this->hostDB . ';dbname=' . $this->nameDB,
'username' => $this->userDB,
'password' => $this->passDB,
'charset' => 'utf8',
]);
$sql = file_get_contents(Yii::getAlias('@app//config/structure.sql'));
$sql .= "INSERT INTO `user` (`userid`, `login`, `accessid`, `fname`, `lname`, `email`, `password`, `block`, `manyTimes`, `blockTimes`) VALUES
(2, '" . $this->login . "', 3, '" . $this->fName . "', '" . $this->lName . "', '" . $this->email . "', '', 0, 0, '0000-00-00 00:00:00');";
$db->createCommand($sql)->queryAll();
This way shows me access denit even though the data is correct.
I have the same problem with sending an email.
$mailer = new yii\swiftmailer\Mailer([
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => $this->smtp,
'username' => $this->userMail,
'password' => $this->passMail,
'port' => $this->portMail,
'encryption' => $this->encryptionMail,
],
]);
$mailer->compose()
->setFrom($this->adminEmail)
->setTo('email@domain')
->setSubject(Yii::$app->name . " - New application.")
->setTextBody('New server: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])
->send();
Please help.