2016-06-02 11 views
0
$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; 

Die obige Abfrage ich jetzt in MySQL geschrieben habe ich wollte nur in CakePHP schreiben 3.CakePHP 3 Groß- und Kleinschreibung Abfrage

I

$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'] 
     ] 
    ]); 

versucht haben und

$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'] 
     ] 
    ]); 

Aber es ist Fehler werfen.

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

+1

Welchen Fehler wirft es? – Alex

+0

Hallo @Alex hier ist der Fehler ..! Fehler: SQLSTATE [42000]: Syntaxfehler oder Zugriffsverletzung: 1064 Sie haben einen Fehler in Ihrer SQL-Syntax; Überprüfen Sie das Handbuch, das Ihrer MySQL-Server-Version entspricht, um die richtige Syntax in der Nähe von ''),'% m-% d-% Y'') = '06 -01-2016 'UND (' LOWER'-Status' Erfolg 'zu verwenden) OR 'status' = 'DEFE' at line 1 –

+0

Wahrscheinlich nur fehlende Klammern:. '[ 'LOWER (Status)'=> 'Erfolg'],' s Ihre Fehlermeldung –

Antwort

0

Vielen Dank für Ihre Antwort. Ich habe die Lösung.

$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; 
Verwandte Themen