skip to Main Content

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?

2

Answers


  1. 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:

    • 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)
    Login or Signup to reply.
  2. if you cant downgrade your php version
    Medium Article
    you can use this solution

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search