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

<pre><code>$tables=preg_split('/\s*,\s*/u',trim($tables),-1,PREG_SPLIT_NO_EMPTY);
</code></pre>

<p>The <a href="http://www.php.net/manual/en/function.preg-split.php" rel="nofollow"><code>preg_split</code> documentation</a> 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.</p>

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

<p>Some trial and error later and adding the <a href="http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php" rel="nofollow"><code>PCRE_UTF8</code> modifier</a> <code>u</code> to the <code>preg_split</code> patterns seemed to solve the problem.</p>

<p>Unfortunately can't explain what's causing the encoding issues yet.</p>

CC BY-SA 3.0
2014-07-07T15:29:54.527Z
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
CC BY-SA 3.0
2014-07-07T19:14:57.820Z
@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...?
Adam Gilleard
CC BY-SA 3.0
2014-07-07T19:44:50.427Z
Yeah, that looks correct... really strange.  Have you tried re-saving all your template files with UTF-8 encoding?
Brad Bell
CC BY-SA 3.0
2014-07-08T12:50:51.313Z
@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?
Adam Gilleard
CC BY-SA 3.0
2014-07-08T14:47:14.080Z
Not entirely sure... probably worth using something like Sublime and explicitly resaving as UTF-8.
Brad Bell
CC BY-SA 3.0
2014-07-07T09:18:20.590Z
2014-07-07T09:18:20.590Z
Adam Gilleard
<p>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?</p>

CC BY-SA 3.0
2014-07-03T16:59:59.497Z
2014-07-03T16:59:59.497Z
Brad Bell
<p>Seeing the above error, somewhat sporadically, and can't seem to track it down.</p>

<p>Here's the full log entry:</p>

<pre><code>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-&gt;buildQuery(Array)
#1 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(484): CDbCommand-&gt;getText()
#2 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(415): CDbCommand-&gt;queryInternal('fetch', Array, Array)
#3 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(410): CDbCommand-&gt;queryRow()
#4 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(146): Craft\AppBehavior-&gt;getInfo('edition')
#5 [internal function]: Craft\AppBehavior-&gt;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-&gt;__call('getEdition', Array)
#8 /var/www/topsecret.co.uk/craft/app/services/LocalizationService.php(111): Craft\WebApp-&gt;getEdition()
#9 /var/www/topsecret.co.uk/craft/app/services/LocalizationService.php(141): Craft\LocalizationService-&gt;getSiteLocales()
#10 /var/www/topsecret.co.uk/craft/app/services/LocalizationService.php(154): Craft\LocalizationService-&gt;getPrimarySiteLocale()
#11 /var/www/topsecret.co.uk/craft/app/etc/web/WebApp.php(824): Craft\LocalizationService-&gt;getPrimarySiteLocaleId()
#12 /var/www/topsecret.co.uk/craft/app/etc/web/WebApp.php(291): Craft\WebApp-&gt;_getTargetLanguage()
#13 /var/www/topsecret.co.uk/craft/app/framework/i18n/CMessageSource.php(83): Craft\WebApp-&gt;getLanguage()
#14 /var/www/topsecret.co.uk/craft/app/framework/YiiBase.php(585): CMessageSource-&gt;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-&gt;buildQuery(Array)
#17 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(484): CDbCommand-&gt;getText()
#18 /var/www/topsecret.co.uk/craft/app/framework/db/CDbCommand.php(415): CDbCommand-&gt;queryInternal('fetch', Array, Array)
#19 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(410): CDbCommand-&gt;queryRow()
#20 /var/www/topsecret.co.uk/craft/app/etc/behaviors/AppBehavior.php(371): Craft\AppBehavior-&gt;getInfo('maintenance')
#21 [internal function]: Craft\AppBehavior-&gt;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-&gt;__call('isInMaintenance...', Array)
#24 /var/www/topsecret.co.uk/craft/app/etc/web/WebApp.php(145): Craft\WebApp-&gt;isInMaintenanceMode()
#25 /var/www/topsecret.co.uk/craft/app/framework/base/CApplication.php(180): Craft\WebApp-&gt;processRequest()
#26 /var/www/topsecret.co.uk/craft/app/index.php(196): CApplication-&gt;run()
#27 /var/www/topsecret.co.uk/web/index.php(17): require_once('/var/www/topse...')
#28 {main}
</code></pre>

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

<p>Any suggestions would be very much appreciated!</p>

<database>
CDbException: The DB query must contain the "from" portion
# CDbException: The DB query must contain the "from" portion

(Asked by: username_0 on 2014-07-03)

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!

**Tags:** database

---

## 2 answers

### Answer by username_0 on 2014-07-07. Score: 3 | Accepted answer

Traced the error back to the from function in Yii's craft/app/framework/db/CDbCommand.php:
$tables=preg_split('/\s*,\s*/u',trim($tables),-1,PREG_SPLIT_NO_EMPTY);

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.

> **Comments:**
> **username_1**: 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.  
> **username_0**: @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...?  
> **username_1**: Yeah, that looks correct... really strange.  Have you tried re-saving all your template files with UTF-8 encoding?  
> **username_0**: @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?  
> **username_1**: Not entirely sure... probably worth using something like Sublime and explicitly resaving as UTF-8.  

---

### Answer by username_1 on 2014-07-03. Score: 1

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?


---

