New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking MySQL version to set sql_mode automatically #2012

Merged
merged 2 commits into from Mar 16, 2016
Jump to file or symbol
Failed to load files and symbols.
+24 −0
Diff settings

Always

Just for now

Next

Checking MySQL version to set sql_mode automatically

  • Loading branch information...
roadster31 committed Feb 25, 2016
commit 5f756f65672acc0f73cd973dab6e46fe6ab0395e
@@ -89,6 +89,30 @@ protected function initPropel()
$con = Propel::getConnection(ProductTableMap::DATABASE_NAME);
$con->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true);
// MySQL 5.6+ compatibility
$result = $con->query("SELECT VERSION() as version, @@GLOBAL.sql_mode as global_sql_mode, @@SESSION.sql_mode as session_sql_mode");
if ($result && $data = $result->fetch(\PDO::FETCH_ASSOC)) {
if (version_compare($data['version'], '5.6.0', '>=')) {
Tlog::getInstance()->addInfo("Setting global and session sql_mode to NO_ENGINE_SUBSTITUTION");
$setQuery = '';
if ($data['global_sql_mode'] != 'NO_ENGINE_SUBSTITUTION') {
$setQuery .= "SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';";
}
if ($data['session_sql_mode'] != 'NO_ENGINE_SUBSTITUTION') {
$setQuery .= "SET SESSION sql_mode='NO_ENGINE_SUBSTITUTION';";
}
if (! empty($setQuery)) {
if (null === $con->query()) {
throw new \RuntimeException('Failed to set MySQL 5.6+ global sql_mode to NO_ENGINE_SUBSTITUTION');
}
}
}
}
if ($this->isDebug()) {
// In debug mode, we have to initialize Tlog at this point, as this class uses Propel
Tlog::getInstance()->setLevel(Tlog::DEBUG);
ProTip! Use n and p to navigate between commits in a pull request.