Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using transaction isolation level breaks the whole database connection #50688

Closed
mwikberg-virta opened this issue Mar 21, 2024 · 1 comment · Fixed by #50689
Closed

Using transaction isolation level breaks the whole database connection #50688

mwikberg-virta opened this issue Mar 21, 2024 · 1 comment · Fixed by #50689

Comments

@mwikberg-virta
Copy link
Contributor

Laravel Version

11.0.7

PHP Version

8.3.3

Database Driver & Version

MySQL 8.0+

Description

Since merging #50044, it's no longer possible to specify the transaction isolation level for a (MySQL) connection. The code now bundles all the "SET" statements, but that causes wrong syntax:

SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED, NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci', SESSION sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

Which causes the following exception:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci', SESSION sql_mode='ONLY_FULL_GROU' at line 1

The transaction isolation level must apparently be set in a separate statement to actually work.

Steps To Reproduce

Configure a (MySQL) database with isolation level, like:

      'replica' => [
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'database' => env('DB_DATABASE', 'forge'),
            'driver' => 'mysql',
            'engine' => 'innodb',
            'host' => env('DB_REPLICA_HOST', env('DB_HOST', '127.0.0.1')),

            // This currently does not work
            'isolation_level' => 'READ UNCOMMITTED',

            'password' => env('DB_PASSWORD', ''),
            'port' => env('DB_PORT', '3306'),
            'prefix' => '',
            'prefix_indexes' => true,
            'sslmode' => env('DB_SSLMODE', 'require'),
            'strict' => true,
            'unix_socket' => env('DB_SOCKET', ''),
            'username' => env('DB_USERNAME', 'forge'),
        ],

and run any command using that connection, like User::connection('replica')->all().

@driesvints
Copy link
Member

Thanks! seems you sent in a PR so let's see how it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants