Skip to content

Commit

Permalink
Backport MySQL connection config option
Browse files Browse the repository at this point in the history
From pull request silverstripe#9721
  • Loading branch information
Adrian Humphreys committed Nov 23, 2020
1 parent 61435c6 commit 9220bf3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ORM/Connect/MySQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*
Expand Down Expand Up @@ -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'));

This comment has been minimized.

Copy link
@mfendeksilverstripe

mfendeksilverstripe Nov 29, 2020

This can be improved to $this->config()->get('sql_mode') which is something more inline with a non-static method call.


if (isset($parameters['timezone'])) {
$this->selectTimezone($parameters['timezone']);
Expand Down

0 comments on commit 9220bf3

Please sign in to comment.