I have an account settings table which stores key-value paired settings for accounts. It has 3 columns: account_ID, key, value and its primary key is composite (account_ID, key).
I use a db schema cache.
When I try to read account settings, as follows:
public function getAccountSettings()
{
return $this->hasMany(AccountSetting::className(), ['account_ID' => 'ID'])->inverseOf('account');
}
public function getSetting($key, $default = null) {
$retval = $this->getAccountSettings()->select(['value'])->where(['key' => $key])->scalar();
if($retval !== false) return $retval;
return $default;
}
, it works as a charm in my dev server (both web and console). In prod server, it works as well in a web controller, however the same call gives an error in a console controller which I call by a shell command.
I don't understand why a console controller in the prod server differs. It's an odd behavior.
Dev server uses MySQL while prod server uses MariaDb. But it still doesn't explain the difference between the web and the console controllers.
Extra note: In SimpleConditionBuilder, getColumn() from ExpressionInterface is put as a parameter to strpos, but getColumn() seems to return mixed, not string.
I expect console application works like web application and gives no error.
PHP Warning 'yii\base\ErrorException' with message 'strpos() expects parameter 1 to be string, array given'
in /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/SimpleConditionBuilder.php:40
Stack trace:
0 [internal function]: yii\base\ErrorHandler->handleError(2, 'strpos() expect...', '/home/carbon/pu...', 40, Array)
1 /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/SimpleConditionBuilder.php(40): strpos(Array, '(')
2 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(283): yii\db\conditions\SimpleConditionBuilder->build(Object(yii\db\conditions\SimpleCondition), Array)
3 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(1527): yii\db\QueryBuilder->buildExpression(Object(yii\db\conditions\SimpleCondition), Array)
4 /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/ConjunctionConditionBuilder.php(60): yii\db\QueryBuilder->buildCondition(Object(yii\db\conditions\SimpleCondition), Array)
5 /home/carbon/public_html/vendor/yiisoft/yii2/db/conditions/ConjunctionConditionBuilder.php(35): yii\db\conditions\ConjunctionConditionBuilder->buildExpressionsFrom(Array, Array)
6 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(283): yii\db\conditions\ConjunctionConditionBuilder->build(Object(yii\db\conditions\AndCondition), Array)
7 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(1527): yii\db\QueryBuilder->buildExpression(Object(yii\db\conditions\AndCondition), Array)
8 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(1336): yii\db\QueryBuilder->buildCondition(Object(yii\db\conditions\AndCondition), Array)
9 /home/carbon/public_html/vendor/yiisoft/yii2/db/QueryBuilder.php(235): yii\db\QueryBuilder->buildWhere(Array, Array)
10 /home/carbon/public_html/vendor/yiisoft/yii2/db/ActiveQuery.php(316): yii\db\QueryBuilder->build(Object(yii\db\Query))
11 /home/carbon/public_html/vendor/yiisoft/yii2/db/Query.php(291): yii\db\ActiveQuery->createCommand(Object(yii\db\Connection))
12 /home/carbon/public_html/models/Account.php(139): yii\db\Query->scalar()
13 /home/carbon/public_html/models/forms/Account.php(128): app\models\Account->getSetting('billing_company...')
| Q | A
| ---------------- | ---
| Yii version | 2.0.15.1
| Prod PHP version | 7.1.26
| Prod Operating system | Centos 7.4.1708
| Prod MySQL version | 15.1 Distrib 5.5.60-MariaDB
| Dev PHP version | 7.1.25
| Dev Operating system | MacOS 10.14.2
| Dev MySQL version | 8.0.13
Would you please try 2.0.16?
I've just tried. Same behavior in 2.0.16.
When I trace the returned array from getColumn(), it's a 1-element array:
[0 => 'account_ID']
That's weird. Is it reproduceable with starting clean with basic application template?
I will try it but I have looked at the prod server's bash configuration since the problem only occurs in prod console commands. I think something goes wrong with locale/encoding/line endings.
1) In the beginning, ./yii command itself was giving "no such file or directory" error. I hadn't done any changes on ./yii file in the basic application template before I entered :set fileformat=unix in vi editor and it started working.
2) I've just noticed ./yii has problems with the letter "i" in the commands.
./yii help/index gives:
Unknown command: help/index
Did you mean "help/index"?
./yii help also does not recognize command:
Unknown command: help
Did you mean one of these?
- help
- help/index
- help/list
- help/list-action-options
- help/usage
./yii help/usage help/usage works properly. ./yii cache/flush works while ./yii cache/index does not.
Maybe it is a related situation with the main problem. The "i" letter also exists in "account_ID".
Some locale outputs from my console:
$ locale charmap
UTF-8
$ echo $LC_ALL
tr_TR.UTF-8
$ echo $LANG
tr_TR.UTF-8
That is still sounds too weird to reproduce. Unfortunately we can't fix it if it's not reproducible.
I will try it but I have looked at the prod server's bash configuration since the problem only occurs in prod console commands. I think something goes wrong with locale/encoding/line endings.
- In the beginning, ./yii command itself was giving "no such file or directory" error. I hadn't done any changes on ./yii file in the basic application template before I entered
:set fileformat=unixin vi editor and it started working.- I've just noticed ./yii has problems with the letter "i" in the commands.
./yii help/index gives:Unknown command: help/index
Did you mean "help/index"?./yii help also does not recognize command:
Unknown command: help
Did you mean one of these?
- help
- help/index
- help/list
- help/list-action-options
- help/usage
./yii help/usage help/usage works properly. ./yii cache/flush works while ./yii cache/index does not.
Maybe it is a related situation with the main problem. The "i" letter also exists in "account_ID".
Some locale outputs from my console:
$ locale charmap UTF-8 $ echo $LC_ALL tr_TR.UTF-8 $ echo $LANG tr_TR.UTF-8
Hi,
I could reproduce issue exactly on web also. Problem is related to Turkish Locale and only produced on PHP 7.2.18 on centos 7. Changing locale to English solves the problem but formatter does not seems to work with locale also.
Regards
Hi again this is not related to the yii2. this bug is propably from php itself. So you can close it.
Probably related bug is here https://bugs.php.net/bug.php?id=18556
Regards