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

Not default connection collation #265

Open
sizov82 opened this issue Mar 29, 2023 · 3 comments
Open

Not default connection collation #265

sizov82 opened this issue Mar 29, 2023 · 3 comments
Labels

Comments

@sizov82
Copy link

sizov82 commented Mar 29, 2023

How to set not default collation for connection?
I`m using utf8mb4 charset and utf8mb4_unicode_ci,
but i cant set collation. Default collation is utf8mb4_general_ci
I cant disable builtin "SET NAMES utf8mb4" and cant override in $dumpSettings['init_commands'], because the builtin commands come after the user commands.

If i add "SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci" to 'init_commands' i get it:
$dumpSettings['init_commands'] dump
array (3) [
0 => string (44) "SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci"
1 => string (17) "SET NAMES utf8mb4"
2 => string (22) "SET TIME_ZONE='+00:00'"
]

@phpony
Copy link
Contributor

phpony commented Mar 29, 2023

As far as I can see, default-character-set is the dump setting you need and it's just a string variable passed directly into SET NAMES query. So you can specify there not only charset but the collation too. Could you try this approach?

$dump = new IMysqldump\Mysqldump('mysql:host=localhost;dbname=testdb', 'username', 'password', ['default-character-set' => 'utf8mb4 COLLATE utf8mb4_unicode_ci']);

@sizov82
Copy link
Author

sizov82 commented Mar 30, 2023

The first thing I tried to do was to do exactly that, but quickly realized that it was not possible because this array value ('default-character-set') is used elsewhere in the class and the "COLLATE" clause is invalid there.

For example this class code generates a commented Mysql command:
"/*!40101 SET character_set_client = " . $this->dumpSettings['default-character-set'] . " */;"

@ifsnop
Copy link
Owner

ifsnop commented May 16, 2023

Maybe we could create an additional option "default-character-collation" that can be sent to the connection string, appending it to SET NAMES. What do you think?

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

No branches or pull requests

3 participants