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


500 Error for CODE error. Connection error.

To test the connection, you can just go,



print_r(Yii::app()->db); // Yii 1.1.x framework

      

Hello

0


source


If you want to test db connection use getIsActive()

yii \ db \ Connection Class method . For more information check this link



0


source


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







All Articles