Home >Backend Development >PHP Tutorial >Laravel WhereIn and GroupBy: How to Fix 'Syntax error or access violation: 1055'?
In Laravel, a common issue arises when attempting to combine the WhereIn and GroupBy methods in a single query, resulting in the dreaded "Syntax error or access violation: 1055" error.
To address this error, consider the following options:
In the config/database.php file, locate the MySQL connection configuration array. Add the following line:
'mysql' => [ ... 'strict' => false, ... ]
By setting strict to false, all strict options will be disabled, allowing the query to execute without encountering the error.
Alternatively, you can selectively enable specific strict modes while keeping the general strict mode enabled. Add the following lines:
'mysql' => [ ... 'strict' => true, 'modes' => [ // 'ONLY_FULL_GROUP_BY', // Disable this to allow grouping by one column 'STRICT_TRANS_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'ERROR_FOR_DIVISION_BY_ZERO', 'NO_AUTO_CREATE_USER', 'NO_ENGINE_SUBSTITUTION' ], ... ]
In this case, the ONLY_FULL_GROUP_BY mode is disabled, allowing grouping by a single column while the other strict modes remain active.
By implementing these solutions, you can resolve the "Syntax error or access violation: 1055" error and successfully execute your query combining WhereIn and GroupBy.
The above is the detailed content of Laravel WhereIn and GroupBy: How to Fix 'Syntax error or access violation: 1055'?. For more information, please follow other related articles on the PHP Chinese website!