Cakephp 3 区分大小写的查询
Cakephp 3 case sensitive query
$date = date("Y-m-d");
$prev_date = date('m-d-Y', strtotime($date .' -1 day'));
$q = "SELECT `id`, `external_id`, `status`, DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y') as crt, `extras`
FROM `gshuplogs` WHERE DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y') = '$prev_date' and
(BINARY `status` in ('success','DEFERRED') or `status` IS NULL)";
$conn = \Cake\Datasource\ConnectionManager::get('default');
$res = $conn->execute($q)->fetchAll('assoc');
debug($res);exit;
上面的查询我是用mysql写的,现在只想用cakephp 3写。
我试过了
$res = $this->Gshuplogs->find()->select([
'id', 'external_id', 'status', 'created'
])->where([
"DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y')" => $prev_date,
'OR' => [
['LOWER status' => 'success'],
['status' => 'DEFERRED'],
['status IS NULL']
]
]);
和
$res = $this->Gshuplogs->find()->select([
'id', 'external_id', 'status', 'created'
])->where([
"DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y')" => $prev_date,
'OR' => [
['BINARY status' => 'success'],
['status' => 'DEFERRED'],
['status IS NULL']
]
]);
但是报错
Error: 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
'`),'%m-%d-%Y'`) = '06-01-2016' AND (`LOWER` status 'success' OR `status` =
'DEFE' at line 1
感谢您的回复。我得到了解决方案。
$date = date("Y-m-d");
$prev_date = date('m-d-Y', strtotime($date .' -1 day'));
$res = $this->Gshuplogs->find()->select([
'id', 'external_id', 'status', "created"
])->where([
"FROM_UNIXTIME(`created`,'%m-%d-%Y')" => $prev_date,
'OR' => [
['BINARY(status) in ' => ['success','DEFERRED']],
['status IS NULL']
]
]);
debug($res->toArray());exit;
$date = date("Y-m-d");
$prev_date = date('m-d-Y', strtotime($date .' -1 day'));
$q = "SELECT `id`, `external_id`, `status`, DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y') as crt, `extras`
FROM `gshuplogs` WHERE DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y') = '$prev_date' and
(BINARY `status` in ('success','DEFERRED') or `status` IS NULL)";
$conn = \Cake\Datasource\ConnectionManager::get('default');
$res = $conn->execute($q)->fetchAll('assoc');
debug($res);exit;
上面的查询我是用mysql写的,现在只想用cakephp 3写。
我试过了
$res = $this->Gshuplogs->find()->select([
'id', 'external_id', 'status', 'created'
])->where([
"DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y')" => $prev_date,
'OR' => [
['LOWER status' => 'success'],
['status' => 'DEFERRED'],
['status IS NULL']
]
]);
和
$res = $this->Gshuplogs->find()->select([
'id', 'external_id', 'status', 'created'
])->where([
"DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y')" => $prev_date,
'OR' => [
['BINARY status' => 'success'],
['status' => 'DEFERRED'],
['status IS NULL']
]
]);
但是报错
Error: 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 '`),'%m-%d-%Y'`) = '06-01-2016' AND (`LOWER` status 'success' OR `status` = 'DEFE' at line 1
感谢您的回复。我得到了解决方案。
$date = date("Y-m-d");
$prev_date = date('m-d-Y', strtotime($date .' -1 day'));
$res = $this->Gshuplogs->find()->select([
'id', 'external_id', 'status', "created"
])->where([
"FROM_UNIXTIME(`created`,'%m-%d-%Y')" => $prev_date,
'OR' => [
['BINARY(status) in ' => ['success','DEFERRED']],
['status IS NULL']
]
]);
debug($res->toArray());exit;