2

Running Craft Version 2.6.2994 on an EC2 instance that has PHP 7.0.21, and MySQL v 5.6.37 installed. When I try to create a new Matrix, I get the following error when saving.

When I test this on my localhost, which has PHP 7.1.5 and MySQL 5.6.35 running Valet, everything seems to work fine so I'm not sure if this is an issue with the version of PHP/MySQL, or in the code. I've also tried it with the root MySQL user having full permissions and it still gives the same error.

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: 
Syntax error or access violation: 1064 You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right 
syntax to use near 'COLLATE=' at line 9

The entire project shows 'COLLATE=' appears in ~2 locations:

MysqlSchema.php, LN 198:

$options = 'ENGINE='.$engine.' DEFAULT CHARSET='.craft()->config->get('charset', ConfigFile::Db).' COLLATE='.craft()->config->get('collation', ConfigFile::Db).($options ? ' '.$options : '');`

And DbHelper.php, LN 219:

$def .= ' COLLATE '.$config['collation'];

Current Plugins Installed:

Edit: Full stack trace:

2017/11/07 16:28:18 [error] [system.db.CDbCommand] CDbCommand::execute() failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLLATE=' at line 9. The SQL statement executed was: CREATE TABLE `craft_matrixcontent_test` (
        `id` int(11) NOT NULL AUTO_INCREMENT,
        `elementId` INT(11) NOT NULL,
        `locale` CHAR(12) NOT NULL,
        `dateCreated` datetime NOT NULL,
        `dateUpdated` datetime NOT NULL,
        `uid` CHAR(36) NOT NULL DEFAULT 0,
        PRIMARY KEY (id)
) ENGINE=InnoDb DEFAULT CHARSET= COLLATE=.
2017/11/07 16:28:18 [error] [exception.CDbException] CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLLATE=' at line 9 in /var/www/craft/app/framework/db/CDbCommand.php:358
Stack trace:
#0 /var/www/craft/app/framework/db/CDbCommand.php(1352): CDbCommand->execute()
#1 /var/www/craft/app/etc/db/DbCommand.php(507): CDbCommand->createTable('craft_matrixcon...', Array, NULL)
#2 /var/www/craft/app/services/MatrixService.php(1071): Craft\DbCommand->createTable('craft_matrixcon...', Array)
#3 /var/www/craft/app/services/MatrixService.php(535): Craft\MatrixService->_createContentTable('matrixcontent_t...')
#4 /var/www/craft/app/fieldtypes/MatrixFieldType.php(152): Craft\MatrixService->saveSettings(Object(Craft\MatrixSettingsModel), false)
#5 /var/www/craft/app/services/FieldsService.php(646): Craft\MatrixFieldType->onAfterSave()
#6 /var/www/craft/app/controllers/FieldsController.php(122): Craft\FieldsService->saveField(Object(Craft\FieldModel))
#7 /var/www/craft/app/framework/web/actions/CInlineAction.php(49): Craft\FieldsController->actionSaveField()
#8 /var/www/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#9 /var/www/craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#10 /var/www/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#11 /var/www/craft/app/framework/web/CWebApplication.php(282): CController->run('saveField')
#12 /var/www/craft/app/etc/web/WebApp.php(823): CWebApplication->runController('fields/saveFiel...')
#13 /var/www/craft/app/etc/web/WebApp.php(287): Craft\WebApp->_processActionRequest()
#14 /var/www/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#15 /var/www/craft/app/index.php(62): CApplication->run()
#16 /var/www/public/index.php(31): require_once('/var/www/craft/...')
#17 {main}
REQUEST_URI=/admin/settings/fields/new?groupId=3
HTTP_REFERER=http://ipaddress/admin/settings/fields/new?groupId=3
---
5
  • MysqlSchema.php, the $options variable is returning ENGINE=InnoDb DEFAULT CHARSET= COLLATE= with craft()->config->get('collation',ConfigFile::Db) returning Null. Not sure where thats supposed to be getting its value. On local host, it returns the correct value, but not in the EC2 instance..
    – jassok
    Nov 7 '17 at 17:03
  • Super weird... are you setting any of those config settings in craft/config/db.php?
    – Brad Bell
    Nov 8 '17 at 3:46
  • Also... everything else works fine? It's just when creating a new Matrix field? Maybe you're running into your php.ini file's post_max_size/max_input_vars values?
    – Brad Bell
    Nov 8 '17 at 3:50
  • Not entirely sure why, perhaps a permission error, but the craft()->config->get() function wasn't able to pull in the default values like it normally does for collation and charset. Adding those both into the db.php settings fixed the issue though.
    – jassok
    Nov 13 '17 at 18:17
  • Yeah... that's strange. Regardless, glad you got it sorted!
    – Brad Bell
    Nov 13 '17 at 18:20
2

Adding the following to db.php fixed the error:

'collation' => 'utf8_unicode_ci',
'charset' => 'utf8'

My guess is that there was some permission issue that was stopping it from getting those automatically, but I'm not entirely sure how they grab the values if its not set by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.