request sql on cakephp -
i'm trying execute long , complex sql request on cakephp . documentation found 2 solution. first call connection manager , pass request string second execute php. problem request complex couldn't find proper way on php.
this request :
select * flight_schedules fs left join weekly_schedules ws on fs.code = ws.code left join structures s on fs.structure_ref = s.id fs.c_code = "xxx" , date_format(fs.flight_start, '%y-%m-%d') <= date_format(now(), '%y-%m-%d') , date_format(now(), '%h:%i:%s') >= date_format(date_sub(fs.flight_start,interval 1 hour) , '%h:%i:%s') , date_format(now(), '%h:%i:%s') <= date_format(fs.flight_end, '%h:%i:%s') , ( date_format(now(), '%y-%m-%d') between date_format(fs.flight_start, '%y-%m-%d') , date_format(fs.flight_end, '%y-%m-%d')) or ( fs.flight_end null , (dayofweek(now()) + ws.monday = 3 or dayofweek(now()) + ws.tuesday = 4 or dayofweek(now()) + ws.wednesday = 5 or dayofweek(now()) + ws.thursday = 6 or dayofweek(now()) + ws.friday = 7 or dayofweek(now()) + ws.saturday = 8 or dayofweek(now()) + ws.sunday = 2 )) order date_format(fs.flight_start, '%h:%i:%s') limit 1
try this;
"conditions" => [ "fs.c_code" => "xxx", "date_format(fs.flight_start, '%y-%m-%d') <= " => "date_format(now(), '%y-%m-%d')", "date_format(now(), '%h:%i:%s') >= " => "date_format(date_sub(fs.flight_start,interval 1 hour) , '%h:%i:%s')", "date_format(now(), '%h:%i:%s')" => "date_format(fs.flight_end, '%h:%i:%s')", "date_format(fs.flight_start, '%y-%m-%d') <= " => "(date_format(now(), '%y-%m-%d')", "date_format(fs.flight_end, '%y-%m-%d') >= " => "(date_format(now(), '%y-%m-%d')", "or" => [ "fs.flight_end" => null, [ "dayofweek(now()) + ws.monday" => 3, "or"=>[ "dayofweek(now()) + ws.tuesday" => 4, "dayofweek(now()) + ws.wednesday" => 5, "dayofweek(now()) + ws.thursday" => 6, "dayofweek(now()) + ws.friday" => 7, "dayofweek(now()) + ws.saturday" => 8, "dayofweek(now()) + ws.sunday" => 2 ] ], ] ], //do order , limit here
sorry, forget wrap it. check update one.
Comments
Post a Comment