$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;
The above query I have written in mysql now I just wanted to write in cakephp 3.
I have tried
$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']
]
]);
AND
$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']
]
]);
But it is throwing error.
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