all of a sudden my laravel app has stopped connecting to SQL server database. No matter what i do, i get the error
SQLSTATE[IMSSP]: An invalid attribute was designated on the PDO object.
I am able to connect to the database as usual from Microsoft Management Studio and as far as i am concerned nothing has change to the server configuration.
The OS of the server is AlmaLinux 8.8 and it has been running well for the last couple of months that the project started.
Route::get('/check_db', function() {
try {
DB::connection('sqlsrv')->getPDO();
echo DB::connection()->getDatabaseName();
} catch (Exception $e) {
echo 'None';
}
});
Adding the above line on the web.php
and visiting the link i get None
PHP version 8.2.9
PS. It works great with MySQL databases.
PS2. Before you downgrade for duplicate, i need to mention that i already searched everything on stackoverflow and laracasts for this specific error and nothing helped me resovle it.
Any info on what is going wrong?
2
Answers
The reason is PHP 8.1.22 and 8.2.9 contain a fix for MySQL which uncovered a bug in sqlsrv extension: one of PDO attributes isn’t supported in the extension and returns an error if set. More information can be found in this Drupal thread.
The error should be fixed by this merged pull request but I have no idea when will it be released.
In the meantime you can either:
or
PDO::ATTR_STRINGIFY_FETCHES
insqlsrv
section ofconfig/database.php
and in$options
ofvendor/laravel/framework/src/Illuminate/Database/Connectors/SqlServerConnector.php
(those changes should be reverted once the fixed sqlsrv extension will be released)if you cant downgrade your php version
Medium Article
you can use this solution