From 9220bf300da3c0862231dc090e9fd606bb1981de Mon Sep 17 00:00:00 2001 From: Adrian Humphreys Date: Mon, 23 Nov 2020 14:05:01 +1300 Subject: [PATCH] Backport MySQL connection config option From pull request https://github.com/silverstripe/silverstripe-framework/pull/9721 --- src/ORM/Connect/MySQLDatabase.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ORM/Connect/MySQLDatabase.php b/src/ORM/Connect/MySQLDatabase.php index c1900488519..ebecab41749 100644 --- a/src/ORM/Connect/MySQLDatabase.php +++ b/src/ORM/Connect/MySQLDatabase.php @@ -49,6 +49,16 @@ class MySQLDatabase extends Database implements TransactionManager */ private static $charset = 'utf8'; + /** + * SQL Mode used on connections to MySQL. Defaults to ANSI. For basic ORM + * compatibility, this setting must always include ANSI or ANSI_QUOTES. + * + * @config + * @var string + */ + private static $sql_mode = 'ANSI'; + + /** * Cache for getTransactionManager() * @@ -84,8 +94,8 @@ public function connect($parameters) // Notify connector of parameters $this->connector->connect($parameters); - // This is important! - $this->setSQLMode('ANSI'); + // Set sql_mode + $this->setSQLMode(static::config()->get('sql_mode')); if (isset($parameters['timezone'])) { $this->selectTimezone($parameters['timezone']);