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

DBWrapper + SQL_MODES #16

Open
KarelWintersky opened this issue Oct 5, 2023 · 0 comments
Open

DBWrapper + SQL_MODES #16

KarelWintersky opened this issue Oct 5, 2023 · 0 comments

Comments

@KarelWintersky
Copy link
Collaborator

В конструктор надо добавить в $options возможность итерации по массиву sql_modes

'ONLY_FULL_GROUP_BY' => true|false

Для true:
SET @@sql_mode = CONCAT(@@sql_mode, ',', 'ONLY_FULL_GROUP_BY');
Для false:

SET @@sql_mode =
        REPLACE(
        REPLACE(
        REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),
                           ',ONLY_FULL_GROUP_BY', ''),
                            'ONLY_FULL_GROUP_BY', '');

и тому подобное для остальных режимов

  • документация по значениям по умолчанию

https://dba.stackexchange.com/questions/112739/session-sql-mode-default-sql-mode
https://dba.stackexchange.com/questions/237048/1055-expression-1-of-select-list-is-not-in-group-by-clause-and-contains-nonag

https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html

https://habr.com/en/articles/166411/

Интересно что:
https://www.php.net/manual/en/pdo.construct.php

PDO::__construct() ( string $dsn [, string $username [, string $password [, array $driver_options ]]] )

То есть можно сказать:

$db = new PDO(
  'mysql:host=myhost;dbname=mydb', 
  'login', 
  'password', 
  array(
    PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode = 'TRADITIONAL'"
  )
);

или

$db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET sql_mode = 'TRADITIONAL'");

Сейчас эта возможность просто игнорируется...

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

No branches or pull requests

1 participant