Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 10 stopped working with SQL Server Database

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

phpinfo() output enter image description here

enter image description here

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?

like image 361
John Gkouziotis Avatar asked May 22 '26 16:05

John Gkouziotis


1 Answers

EDIT (2023-09-30)

The updated version 5.11.1 of (pdo_)sqlsrv has been released in the beginning of September (github tag). It contains the pull request mentioned below.

Previous answer

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 return an error if set. More information can be found in this Drupal thread.

The error should be fixed by this merged pull request in next release.

In the meantime you can either:

  • downgrade PHP version (and keep it from updating if possible)

or

  • temporarily comment out PDO::ATTR_STRINGIFY_FETCHES in sqlsrv section of config/database.php and in $options of vendor/laravel/framework/src/Illuminate/Database/Connectors/SqlServerConnector.php (those changes should be reverted once the fixed sqlsrv extension will be released)
like image 75
bjauy Avatar answered May 24 '26 05:05

bjauy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!