How to solve 500 errors when connecting Yii Db
I have uploaded the yii framework to my server. I am using string to connect db
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=smargavc_Konnections',
'username' => 'smargavc_Konnect',
'password' => '******',
'charset' => 'utf8',
];
Here Wheather doesn't know if the db is connected or not.
When I try in postman to access the rest of the call getting 500 errro
-1
source to share
3 answers
I had a response config in web.php. This caused a 500 error issue.
'response' => [
'class' => 'yii\web\Response',
'on beforeSend' => function ($event) {
$response = $event->sender;
if ($response->data !== null && !empty(Yii::$app->request->get('suppress_response_code'))) {
$response->data = [
'success' => $response->isSuccessful,
'data' => $response->data,
];
$response->statusCode = 200;
}
},
],
I had this in my config. I don't know the reason. But it solves my problem.
0
source to share