这可能是一个特殊问题,我确实需要第二只眼睛。我在我的PHP脚本中运行以下查询,但在查询中找到错误的行时遇到问题。当我回显$查询时,我看到输出有效,但查询给出并在输出结尾处出错:
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'')附近使用正确的语法,('1','$ GPRMC','040837.002','A','60.15465','N','24.7436' ,'E','0.5',1970,01,01''在第1行
我正在运行以下查询:
query = "INSERT INTO rmc_raw_data
(device_id, nmea, rmc_time, signal, latitude, north, longitude, east, speed, track_angle, rmc_date, magnetic_variation, west,check_sum)
VALUES";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$numlines++;
$myDay=substr($data[9], 0,2);
$myMonth=substr($data[9], 2,2);
$myYear=substr($data[9], 4,2);
$rmc_date = convertToNiceDate($myDay, $myMonth, 2000+$myYear);
$longitude = convertToDegrees($data[6]);
$latitude = convertToDegrees($data[4]);
$query .= "('$data[0]','$data[1]','$data[2]','$data[3]','$latitude','$data[5]','$longitude','$data[7]','$data[8]',$rmc_date','$data[10]','$data[11]','$data[12]'),";
}
$query = substr($query, 0,-1);
echo $query;
mysql_query($query) or die(mysql_error());
查询从文本文件中导入和操作数据,该文件具有以逗号分隔的以下数据行样本:
//input data
1,$GPRMC,080323.460,A,6013.45368,N,02445.28396,E,21.6,134.0,070610,6.9,W,A*2A
1,$GPRMC,080327.000,A,6013.44424,N,02445.31214,E,9.0,135.2,070610,6.9,W,A*1E
1,$GPRMC,132305.000,V,,,,,,,070610,,,N*4B
1,$GPRMC,132320.000,V,,,,,,,070610,,,N*4C
1,$GPRMC,132335.000,V,,,,,,,070610,,,N*48
1,$GPRMC,132350.000,V,,,,,,,070610,,,N*4B
1,$GPRMC,134841.000,V,,,,,,,070610,,,N*46
1,$GPRMC,134856.000,A,6009.32417,N,02444.63687,E,1.7,124.8,070610,6.9,W,A*1A
1,$GPRMC,134911.000,A,6009.32239,N,02444.63356,E,,,070610,,,A*64
1,$GPRMC,134927.000,V,,,,,,,070610,,,N*47
1,$GPRMC,155411.405,V,,,,,,,070610,,,N*49
-------
虽然查询在我测试时将结果输出到屏幕,但它在输出的下一个点也给出了错误,即它终止的位置:
//output data to be inserted
('1','$GPRMC','142346.000','A','60.15675','N','24.74189','E','14.1',1970,01,01','290610','6.9','W'), ('1','$GPRMC','142349.000','A','60.15656','N','24.74203','E','13.5',1970,01,01','290610','6.9','W'), ('1','$GPRMC','142402.000','A','60.15565','N','24.74287','E','13.2',1970,01,01','290610','6.9','W'), ('1','$GPRMC','142411.000','A','60.1551','N','24.74347','E','7.3',1970,01,01','290610','6.9','W'), ('1','$GPRMC','142414.000','A','60.15507','N','24.74346','E','',1970,01,01','290610','',''), ('1','$GPRMC','142417.000','A','60.15514','N','24.74358','E','6.4',1970,01,01','290610','6.9','W'), ('1','$GPRMC','142423.000','A','60.15524','N','24.74371','E','',1970,01,01','290610','',''), ('1','$GPRMC','142435.000','A','60.15512','N','24.74365','E','',1970,01,01','290610','',''),
('1','$GPRMC','142447.000','V','0','','0','','',1970,01,01','290610','',''),
('1','$GPRMC','142459.000','V','0','','0','','',1970,01,01','290610','',''),
('1','$GPRMC','062917.637','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','062932.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','063206.392','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080238.101','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080253.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080305.000','V','0','','0','','',1970,01,01','070610','',''),
('1','$GPRMC','080308.000','V','0','','0','','',1970,01,01','070610','','')
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 '','070610','6.9','W'),('1','$GPRMC','080327.000','A','60.22407','N','24.7552','E' at line 1
我一直在努力追踪错误但没有解决方案。我已经获得了相同的结果与文件的类似性质没有疑虑。但这让我疯了。
答案 0 :(得分:2)
$rmc_date
未正确引用。
答案 1 :(得分:2)
“$ rmc_date”
附近缺少引号