В основном таблица ProductOffer.Миграция
$this->createTable('product_offer', [
'id' => $this->primaryKey(),
'product_id' => $this->bigInteger(20) . ' NOT NULL',
'customer_id' => $this->bigInteger(20),
'coupon_code' => $this->string(),
'offer' => $this->string(),
'customer_name' => $this->string(),
'email_address' => $this->string(),
'phone_number' => $this->string(),
'note' => $this->text(),
'admin_note' => $this->text(),
'status' => $this->tinyInteger(),
'created' => $this->dateTime() . ' NOT NULL',
'modified' => $this->dateTime(),
]);
Теперь у меня есть данные в этой таблице и создан запрос.
<code>$stamp = mktime(0, 0, 0);
$testQuery = self::find()->where([
'and',
['=', 'status', self::STATUS_REJECTED],
['=', 'product_id', $this->product_id],
['=', 'email_address', $this->email_address],
['>', 'created', date('m-d-Y H:i:s',$stamp)]
]);
echo "<pre>";
print_r($testQuery->all());
echo "
";
Результат
Array
(
[0] => app\models\ProductOffer Object
(
[verifyCode] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 48
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => Test
[admin_note] =>
[status] => Rejected
[created] => 2018-05-16 04:38:28
[modified] =>
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 48
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => Test
[admin_note] =>
[status] => 0
[created] => 2018-05-16 04:38:28
[modified] =>
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_relationsDependencies:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_eventWildcards:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[1] => app\models\ProductOffer Object
(
[verifyCode] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 50
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => Test
[admin_note] =>
[status] => Rejected
[created] => 2018-05-17 04:39:55
[modified] =>
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 50
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => Test
[admin_note] =>
[status] => 0
[created] => 2018-05-17 04:39:55
[modified] =>
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_relationsDependencies:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_eventWildcards:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[2] => app\models\ProductOffer Object
(
[verifyCode] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 51
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => test
[admin_note] =>
[status] => Rejected
[created] => 2018-05-17 04:43:29
[modified] =>
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 51
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => test
[admin_note] =>
[status] => 0
[created] => 2018-05-17 04:43:29
[modified] =>
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_relationsDependencies:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_eventWildcards:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[3] => app\models\ProductOffer Object
(
[verifyCode] =>
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 55
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => Test
[admin_note] =>
[status] => Rejected
[created] => 2018-05-17 04:51:57
[modified] =>
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 55
[product_id] => 111
[customer_id] =>
[coupon_code] =>
[offer] => 23
[customer_name] => Aljay Mallari
[email_address] => asrockg07@gmail.com
[phone_number] => 958568574
[note] => Test
[admin_note] =>
[status] => 0
[created] => 2018-05-17 04:51:57
[modified] =>
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_relationsDependencies:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_eventWildcards:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
);
Сегодня в нашем часовом поясе 17.05.2008 г. я хочу получить данные, которые были созданы сегодня, но, похоже, мой запрос не исключает данные, которые были созданы вчера.
Я уже пробовал выразить это
['<', 'created', new Expression('NOW()')]
и это
<code>$testQuery = self::find()->where([
'and',
['=', 'status', self::STATUS_REJECTED],
['=', 'product_id', $this->product_id],
['=', 'email_address', $this->email_address],
['>', 'created', new Expression(date('m-d-Y H:i:s', $stamp))]
]);
echo "<pre>";
print_r($testQuery->all());
echo "
";
И теперь я получаю ошибку SQL
Исключение базы данных - yii \ db \ Exception SQLSTATE [42000]: ошибка синтаксиса или нарушение доступа: 1064 У вас естьошибка в вашем синтаксисе SQL;проверьте руководство, соответствующее вашей версии сервера MySQL, чтобы найти правильный синтаксис для использования рядом с '00: 00: 00) 'в строке 1. Выполняемый SQL был: SELECT * FROM product_offer
WHERE (status
= 0) AND (product_id
= '111') И (email_address
= 'asrockg07@gmail.com') И (created
> 05-17-2018 00:00:00)