From 2f772afdfcb6c8699418faffcd6b0b92dc564ce1 Mon Sep 17 00:00:00 2001 From: Rodrigo Pedra Brum Date: Sun, 22 Apr 2018 19:54:52 -0300 Subject: [PATCH] Added compatibility with MySQL 8.0.11 (GA) --- src/Illuminate/Database/Connectors/MySqlConnector.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Connectors/MySqlConnector.php b/src/Illuminate/Database/Connectors/MySqlConnector.php index 3b12b300ef75..ed341aa45c1c 100755 --- a/src/Illuminate/Database/Connectors/MySqlConnector.php +++ b/src/Illuminate/Database/Connectors/MySqlConnector.php @@ -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())->execute(); + $connection->prepare($this->strictMode($connection))->execute(); } else { $connection->prepare("set session sql_mode='NO_ENGINE_SUBSTITUTION'")->execute(); } @@ -171,10 +171,16 @@ protected function setCustomModes(PDO $connection, array $config) /** * Get the query to enable strict mode. * + * @param \PDO $connection + * * @return string */ - protected function strictMode() + protected function strictMode(PDO $connection) { + if (version_compare($connection->getAttribute(PDO::ATTR_SERVER_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'"; + } + 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_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'"; } }