[php-src] Issue #15386: pdo_mysql error "Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY
clause"

From: Date: Tue, 13 Aug 2024 15:57:34 +0000
Subject: [php-src] Issue #15386: pdo_mysql error "Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY
clause"
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247490@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/15386 Author: francoisjacquet ### Description I am trying to use the pdo_mysql PHP extension with emulation of prepared statements disabled. The code is equivalent to the following: ```php $db_connection = new PDO( $prefix . ':dbname=' . $DatabaseName . ';host=' . $DatabaseServer . ';port=' . $DatabasePort . ';charset=utf8mb4', $DatabaseUsername, $DatabasePassword, [ // @link https://www.php.net/manual/en/pdo.setattribute.php PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT, PDO::ATTR_CASE => PDO::CASE_UPPER, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_STRINGIFY_FETCHES => true, ] ); $sql = "SELECT AVG(CUM_WEIGHTED_GPA) AS CUM_WEIGHTED_GPA, AVG(UNWEIGHTED_GPA) AS CUM_UNWEIGHTED_GPA FROM transcript_grades WHERE SYEAR='2023' AND SCHOOL_ID='1' AND MARKING_PERIOD_ID='4'"; $stmt = $db_connection->query( $sql ); if ( $stmt ) { $stmt->execute(); var_dump( $stmt->errorInfo() ); } ``` The following error is returned: ``` 42000 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause ``` Here are the SQL modes set in MariaDB 10.11.6: ``` ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION ``` The same query is fine when PDO::ATTR_EMULATE_PREPARES => true or when run from the MariaDB console. Please note, the SQL query is **not** a prepared statement. Please also note, [transcript_grades is a VIEW](https://gitlab.com/francoisjacquet/rosariosis/-/blob/mobile/rosariosis_mysql.sql#L2065). I am filing a bug report as I received no help on [DBA stackexchange](https://dba.stackexchange.com/questions/341620/php-pdo-error-mixing-of-group-columns-min-max-count-with-no-group-c). Please bear with me if this is not an actual driver bug. ### PHP Version PHP 8.3.10 ### Operating System Debian bookworm

« previous php.bugs (#247490) next »