Skip to content

Commit

Permalink
Allow overriding the MySQL server version for strict mode (#32708)
Browse files Browse the repository at this point in the history
* Allow overriding the MySQL server version

* Update MySqlConnector.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
Propaganistas and taylorotwell authored May 6, 2020
1 parent c5e88be commit 25730a8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Illuminate/Database/Connectors/MySqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function setModes(PDO $connection, array $config)
$this->setCustomModes($connection, $config);
} elseif (isset($config['strict'])) {
if ($config['strict']) {
$connection->prepare($this->strictMode($connection))->execute();
$connection->prepare($this->strictMode($connection, $config))->execute();
} else {
$connection->prepare("set session sql_mode='NO_ENGINE_SUBSTITUTION'")->execute();
}
Expand All @@ -172,11 +172,14 @@ protected function setCustomModes(PDO $connection, array $config)
* Get the query to enable strict mode.
*
* @param \PDO $connection
* @param array $config
* @return string
*/
protected function strictMode(PDO $connection)
protected function strictMode(PDO $connection, $config)
{
if (version_compare($connection->getAttribute(PDO::ATTR_SERVER_VERSION), '8.0.11') >= 0) {
$version = $config['version'] ?? $connection->getAttribute(PDO::ATTR_SERVER_VERSION);

if (version_compare($version, '8.0.11') >= 0) {
return "set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
}

Expand Down

0 comments on commit 25730a8

Please sign in to comment.