From b87094ac2f502b31b8650c371c01b74b894df50e Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 26 Jul 2016 15:54:22 +0200 Subject: fixes #376, remove option ONLY_FULL_GROUP_BY in sql_mode based on solution provided by Mercury_LABBS on piwigo.org forums --- include/dblayer/functions_mysqli.inc.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/dblayer/functions_mysqli.inc.php b/include/dblayer/functions_mysqli.inc.php index 5b40cfe5b..f0bca9be6 100644 --- a/include/dblayer/functions_mysqli.inc.php +++ b/include/dblayer/functions_mysqli.inc.php @@ -73,6 +73,19 @@ function pwg_db_connect($host, $user, $password, $database) { throw new Exception('Connection to server succeed, but it was impossible to connect to database'); } + + // MySQL 5.7 default settings forbid to select a colum that is not in the + // group by. We've use that in Piwigo, for years. As an immediate solution + // we can remove this constraint in the current MySQL session. + list($sql_mode_current) = pwg_db_fetch_row(pwg_query('SELECT @@SESSION.sql_mode')); + + // remove ONLY_FULL_GROUP_BY from the list + $sql_mode_altered = implode(',', array_diff(explode(',', $sql_mode_current), array('ONLY_FULL_GROUP_BY'))); + + if ($sql_mode_altered != $sql_mode_current) + { + pwg_query("SET SESSION sql_mode='".$sql_mode_altered."'"); + } } /** -- cgit v1.2.3 From 78bf53f45a00855f869e8dbbe35e4de5a46d2f00 Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 26 Jul 2016 16:02:01 +0200 Subject: typo fixed in comment --- include/dblayer/functions_mysqli.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dblayer/functions_mysqli.inc.php b/include/dblayer/functions_mysqli.inc.php index f0bca9be6..21adbeabe 100644 --- a/include/dblayer/functions_mysqli.inc.php +++ b/include/dblayer/functions_mysqli.inc.php @@ -75,7 +75,7 @@ function pwg_db_connect($host, $user, $password, $database) } // MySQL 5.7 default settings forbid to select a colum that is not in the - // group by. We've use that in Piwigo, for years. As an immediate solution + // group by. We've used that in Piwigo, for years. As an immediate solution // we can remove this constraint in the current MySQL session. list($sql_mode_current) = pwg_db_fetch_row(pwg_query('SELECT @@SESSION.sql_mode')); -- cgit v1.2.3