我的网络服务器上安装了一些名为phpVMS的软件,我们正在运行名为SmartCARS的软件,它可以跟踪飞行模拟器上的飞机并将数据发送到phpVMS软件。在飞行结束时,PIREP被提交但由于某种原因我得到MySQL语法错误。这是错误:
SELECT * FROM (
(SELECT c.* FROM sellers c
LEFT JOIN (
SELECT * FROM orders
WHERE order_date BETWEEN DATE(CURDATE() - INTERVAL 2 MONTH) AND NOW()
) d ON c.seller_id = d.seller_id
GROUP BY c.seller_id
HAVING count(d.order_id) >= 10
)
UNION
(SELECT c.* FROM sellers c
LEFT JOIN (
SELECT * FROM orders WHERE order_date BETWEEN DATE(CURDATE() - INTERVAL 15 DAY) AND NOW()
) as d
ON c.seller_id = d.seller_id
WHERE d.seller_id IS NULL)
) derived
我还尝试为DateAdd更改NOW(),但是我在错误日志中使用DateAdd替换NOW()时得到了同样的错误。
任何人都知道如何解决此错误?
这是我能找到的与查询相关的所有代码:
Time: 10.19.17 08:56:52
Backtrace: DB::write_debug > DB::query > PIREPData::fileReport > ACARSData::FilePIREP > smartCARS::filepirep
Query: INSERT INTO phpvms_pireps (`pilotid`, `code`, `flightnum`, `depicao`, `arricao`, `route`, `aircraft`, `load`, `flighttime`, `landingrate`, `submitdate`, `fuelused`, `source`, `log`, `distance`, `rawdata`, `flighttime_stamp`, `exported`, `modifieddate`, `accepted`, `expenselist`, `flighttype`) VALUES ('1', 'MCC', '124', 'EGKK', 'EGKK', '', '24', '140', '00.00', '5537', NOW(), '49', 'smartCARS', 'smartCARS version 2.1.31.0, 2017/10/19 UTC*[07:40:58] Preflight started, flying offline*[07:40:58] Flying FSLabs A320X CFM - Easyjet (new colors) (G-EZTA)*[07:56:02] Engine 1 is on*[07:56:02] Engine 2 is on*[07:56:21] Slew mode entered*[07:56:26] Pushing back with 4979 kg of fuel*[07:56:27] Taxiing to runway*[07:56:36] Taking off*[07:56:38] Climbing, pitch: 0, roll: level, 66 kts*[07:56:42] Touched down early at 5537 fpm, gear level: down, flaps: 0*[07:56:47] Landed in 558 ft, fuel: 4959 kg, weight: 61949 kg*[07:56:47] Taxiing to gate*[07:56:47] The flight may now be ended*[07:56:47] Taxi time was less than 15 seconds*[07:56:47] Arrived, flight duration: 00:00', '0', '', '00:00:00', '0', 'NOW()', '0', '0', 'P');
Error: (1292) - Incorrect datetime value: 'NOW()' for column 'modifieddate' at row 1
=====
我尝试从代码中删除单引号但我收到此错误
$pirepdata['exported'] = 0;
$pirepdata['submitdate'] = 'NOW()';
$pirepdata['modifieddate'] = 'NOW()';
$pirepdata['accepted'] = PIREP_PENDING;
$pirepdata['expenselist'] = '0';
$pirepdata['flighttype'] = $sched->flighttype;
# Do the insert based on the columns here
$cols = array();
$col_values = array();
foreach ($pirepdata as $key => $value) {
if($key == 'submitdate') {
$value = 'NOW()';
} elseif ($key == 'comment') {
continue;
} else {
$value = "'".DB::escape($value)."'";
}
$cols[] = "`{$key}`";
$col_values[] = $value;
}
$cols = implode(', ', $cols);
$col_values = implode(', ', $col_values);
$sql = 'INSERT INTO ' . TABLE_PREFIX . "pireps ({$cols}) VALUES ({$col_values});";
DB::query($sql);
$pirepid = DB::$insert_id;
如果我尝试使用php date函数,我会收到此错误
[25-Oct-2017 09:02:27 Europe/London] PHP Fatal error: Call to undefined function now() in /var/www/fly/core/common/PIREPData.class.php on line 710
[25-Oct-2017 09:02:27 Europe/London] PHP Stack trace:
[25-Oct-2017 09:02:27 Europe/London] PHP 1. {main}() /var/www/fly/core/smartcars/frame.php:0
[25-Oct-2017 09:02:27 Europe/London] PHP 2. smartCARS::filepirep() /var/www/fly/core/smartcars/frame.php:269
[25-Oct-2017 09:02:27 Europe/London] PHP 3. ACARSData::FilePIREP() /var/www/fly/core/smartcars/interface.php:745
[25-Oct-2017 09:02:27 Europe/London] PHP 4. PIREPData::fileReport() /var/www/fly/core/common/ACARSData.class.php:280
答案 0 :(得分:2)
如果按原样运行程序,您会发现$ sql中的值类似于:
function getDriving() {
var url = $('#map').data('request-url2');
$.getJSON(url,
function (data) {
var marker = [];
$.each(data,
function (i, item) {
marker.push({
'location': new google.maps.LatLng(item.Latitude2, item.Longitude2),
'map': map,
'weight': item.Speed,
'radius': 10
});
});
var pointArray = new google.maps.MVCArray(marker);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
});
您会注意到现在(' NOW()'引用了修改日期的值。要解决这个问题,您需要做的就是将foreach中的第一张支票更改为:
INSERT INTO wp_pireps (`exported`, `submitdate`, `modifieddate`, `accepted`, `expenselist`, `flighttype`) VALUES ('0', NOW(), 'NOW()', 'PIREP_PENDING', '0', '');
希望这有帮助。