Seeing the above error, somewhat sporadically, and can't seem to track it down.

Here's the full log entry:

2014/07/03 15:17:22 [error] [exception.CDbException] exception 'CDbException' with message 'The DB query must contain the "from" portion.' in /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php:566
Stack trace:
#0 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(160): CDbCommand->buildQuery(Array)
#1 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(484): CDbCommand->getText()
#2 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(415): CDbCommand->queryInternal('fetch', Array, Array)
#3 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(410): CDbCommand->queryRow()
#4 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(146): Craft\AppBehavior->getInfo('edition')
#5 [internal function]: Craft\AppBehavior->getEdition()
#6 /var/www/topsecret.co.uk/craft/app/framework/base/CComponent.php(261): call_user_func_array(Array, Array)
#7 /var/www/topsecret.co.uk/craft/app/services/LocalizationService.php(111): CComponent->__call('getEdition', Array)
#8 /var/www/topsecret.co.uk/craft/app/services/LocalizationService.php(111): Craft\WebApp->getEdition()
#9 /var/www/topsecret.co.uk/craft/app/services/LocalizationService.php(141): Craft\LocalizationService->getSiteLocales()
#10 /var/www/topsecret.co.uk/craft/app/services/LocalizationService.php(154): Craft\LocalizationService->getPrimarySiteLocale()
#11 /var/www/topsecret.co.uk/craft/app/etc/web/WebApp.php(824): Craft\LocalizationService->getPrimarySiteLocaleId()
#12 /var/www/topsecret.co.uk/craft/app/etc/web/WebApp.php(291): Craft\WebApp->_getTargetLanguage()
#13 /var/www/topsecret.co.uk/craft/app/framework/i18n/CMessageSource.php(83): Craft\WebApp->getLanguage()
#14 /var/www/topsecret.co.uk/craft/app/framework/YiiBase.php(585): CMessageSource->translate('yii', 'The DB query mu...', NULL)
#15 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(566): YiiBase::t('yii', 'The DB query mu...')
#16 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(160): CDbCommand->buildQuery(Array)
#17 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(484): CDbCommand->getText()
#18 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(415): CDbCommand->queryInternal('fetch', Array, Array)
#19 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(410): CDbCommand->queryRow()
#20 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(371): Craft\AppBehavior->getInfo('maintenance')
#21 [internal function]: Craft\AppBehavior->isInMaintenanceMode()
#22 /var/www/topsecret.co.uk/craft/app/framework/base/CComponent.php(261): call_user_func_array(Array, Array)
#23 /var/www/topsecret.co.uk/craft/app/etc/web/WebApp.php(145): CComponent->__call('isInMaintenance...', Array)
#24 /var/www/topsecret.co.uk/craft/app/etc/web/WebApp.php(145): Craft\WebApp->isInMaintenanceMode()
#25 /var/www/topsecret.co.uk/craft/app/framework/base/CApplication.php(180): Craft\WebApp->processRequest()
#26 /var/www/topsecret.co.uk/craft/app/index.php(196): CApplication->run()
#27 /var/www/topsecret.co.uk/web/index.php(17): require_once('/var/www/topse...')
#28 {main}

Looking through that I'm not seeing any references to any custom plugins or templates so wonder if it's a bug...

Any suggestions would be very much appreciated!


Traced the error back to the from function in Yii's craft/app/framework/db/CDbCommand.php:


The preg_split documentation states "if matching fails, an array with a single element containing the input string will be returned" but I was just getting an empty array.

This made me suspicious of what the PREG_SPLIT_NO_EMPTY flag was hiding, sure enough without it I got an array with one empty string in it, as if there was a match.

Some trial and error later and adding the PCRE_UTF8 modifier u to the preg_split patterns seemed to solve the problem.

Unfortunately can't explain what's causing the encoding issues yet.

  • Curious... what's the charset and collation of your database set to? Specifically the craft_info table, since that's the one that seems to be causing the issues.
    – Brad Bell
    Jul 7 '14 at 15:29
  • @BradBell DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci, looks correct to me? I can't explain the irregular occurrence of it. Intermittence I can conceivably blame on caching, but it only effecting homepage requests...? Jul 7 '14 at 19:14
  • Yeah, that looks correct... really strange. Have you tried re-saving all your template files with UTF-8 encoding?
    – Brad Bell
    Jul 7 '14 at 19:44
  • @BradBell the templates are reported as a mix of us-ascii and utf-8 (using file -I). From what I gather us-ascii is a subset of utf-8 though? Jul 8 '14 at 12:50
  • Not entirely sure... probably worth using something like Sublime and explicitly resaving as UTF-8.
    – Brad Bell
    Jul 8 '14 at 14:47

That actually looks like it might be a bug. Can you send a database dump as well as a zip of your craft/storage/runtime/logs folder over to support@buildwithcraft.com so we can investigate?


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.