Skip to content

Instantly share code, notes, and snippets.

@LiamKarlMitchell
Created September 11, 2019 23:57
Show Gist options
  • Save LiamKarlMitchell/5ccebe5aa87b49ce0ae300bdc8e9fa53 to your computer and use it in GitHub Desktop.
Save LiamKarlMitchell/5ccebe5aa87b49ce0ae300bdc8e9fa53 to your computer and use it in GitHub Desktop.
Fix vTiger on mysql that requires set options.

You can change the mysql config to apply the set options.

sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

However this is not always desireable on shared hosting you don't know the follow on effects.

So far, I've found I can simply set this in the installer and the db connection class.

include/database/PearDatabase.php Search for function connect

Apply this code under the if for isdb_default_utf8_charset

                        if($this->isdb_default_utf8_charset) {
                                $this->executeSetNamesUTF8SQL(true);
                        }
                        if ($this->dbType === 'mysql') {
                                $this->database->Execute("SET SESSION sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
                        }

And for the installer

Edit the modules/Install/models/Utils.php After the mysql_server_version = self::getMySQLVersion($serverInfo);

Put this to set the options for the sql mode for the session.

$conn->Execute("SET SESSION sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");

@raksati
Copy link

raksati commented Feb 25, 2022

The condition is not always true (I think based on the PHP version and therefore the MySQL connection libraries), so you need to add this other condition as well:

if ($this->dbType === 'mysqli') {
                                $this->database->Execute("SET SESSION sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
                        }

@LiamKarlMitchell
Copy link
Author

Fair enough, was not in my particular use-case but thanks @raksati sorry if you have to deal with vTiger it can be a pain :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment